Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created April 28, 2018 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebeam7/785fa7bb6cc464a3a0f15b27a047e834 to your computer and use it in GitHub Desktop.
Save icebeam7/785fa7bb6cc464a3a0f15b27a047e834 to your computer and use it in GitHub Desktop.
FaceLoginApp: PaginaRegistro.xaml.cs
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Plugin.Media.Abstractions;
using FaceLoginApp.Modelos;
using FaceLoginApp.Servicios;
namespace FaceLoginApp.Paginas
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PaginaRegistro : ContentPage
{
MediaFile foto1, foto2, foto3;
public PaginaRegistro()
{
InitializeComponent();
}
void Loading(bool mostrar)
{
indicator.IsEnabled = mostrar;
indicator.IsRunning = mostrar;
}
async void btnTomarFoto_Clicked(object sender, EventArgs e)
{
try
{
Loading(true);
if (foto1 == null)
{
foto1 = await ServicioImagen.TomarFoto();
if (foto1 != null)
imagen1.Source = ImageSource.FromStream(foto1.GetStream);
}
else if (foto2 == null)
{
foto2 = await ServicioImagen.TomarFoto();
if (foto2 != null)
imagen2.Source = ImageSource.FromStream(foto2.GetStream);
}
else
{
foto3 = await ServicioImagen.TomarFoto();
if (foto3 != null)
imagen3.Source = ImageSource.FromStream(foto3.GetStream);
}
}
catch (Exception ex)
{
}
finally
{
Loading(false);
}
}
async void btnRegistrar_Clicked(object sender, EventArgs e)
{
if (foto1 != null && foto2 != null && foto3 != null)
{
bool op = false;
try
{
Loading(true);
var nombre = txtNombre.Text;
var personID = await ServicioFace.RegistrarPersonaEnGrupo(nombre);
await ServicioFace.RegistrarRostro(personID, foto1.GetStream());
await ServicioFace.RegistrarRostro(personID, foto2.GetStream());
await ServicioFace.RegistrarRostro(personID, foto3.GetStream());
var usuario = new Usuario()
{
Key = personID.ToString(),
Nombre = nombre,
EmocionActual = "",
FotoActual = "",
ScoreActual = 0
};
op = await new ServicioBaseDatos().RegistrarUsuario(usuario);
}
catch (Exception ex)
{
}
finally
{
if (op)
{
await DisplayAlert("Correcto", "Empleado registrado correctamente", "OK");
await Navigation.PopAsync();
}
else
await DisplayAlert("Error", "Error al registrar el empleado", "OK");
Loading(false);
}
}
else
await DisplayAlert("Error", "Debes tomar 3 fotografías al empleado", "OK");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment