示例#1
0
        public async Task <ActionResult <Refugio> > PostRefugio(Refugio refugio)
        {
            _context.Refugios.Add(refugio);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetRefugio), new { id = refugio.RefugioId }, refugio));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("RefugioId,Nombre,Direccion,Telefono,Email,Contrasenia,Sitio_web")] Refugio refugio)
        {
            if (id != refugio.RefugioId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(refugio);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RefugioExists(refugio.RefugioId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(refugio));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("RefugioId,Nombre,Direccion,Telefono,Email,Contrasenia,Sitio_web")] Refugio refugio)
        {
            Console.WriteLine("Entramos a CREATE");
            if (ModelState.IsValid)
            {
                /*if (refugio.Imagen != null)
                 * {
                 *  string folder = "imgRefugios\\";
                 *  string guid = Guid.NewGuid().ToString() + "_" + refugio.Imagen.FileName;
                 *  folder += guid;
                 *  string serverFolder = Path.Combine(_webHostEnvironment.WebRootPath, folder);
                 *  await refugio.Imagen.CopyToAsync(new FileStream(serverFolder, FileMode.Create));
                 *  refugio.ImagenURL = guid;
                 * }*/
                Console.WriteLine("Se está creando el registro ");
                _context.Add(refugio);
                await _context.SaveChangesAsync();

                Console.WriteLine("Se agregó al contexto");
                TempData["UsuarioCreado"] = "TRUE";
                this.solicitud            = new SolicitudRefugio();
                this.solicitud.RefugioId  = refugio.RefugioId;
                this.solicitud.userId     = this.IdUsr;
                this.solicitud.code       = this.CodeUsr;
                this.solicitud.returnUrl  = this.UrlUsr;
                this.solicitud.EsAceptado = false;
                Console.WriteLine(" Solicitud refugio ID" + this.solicitud.RefugioId);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(refugio));
        }
示例#4
0
        public int RegistrarRefugio(Refugio refugio)
        {
            dbConnection.Insert(refugio);
            int id = dbConnection.ExecuteScalar <int>("SELECT last_insert_rowid()");

            return(id);
        }
示例#5
0
        public async Task <IActionResult> EnvioDatos(String IdUsr, String codeUsr, String urlUsr)
        {
            Console.WriteLine("Aqui voy a guardar la info enviada: " + IdUsr + "  " + codeUsr + " " + urlUsr);
            this.IdUsr   = IdUsr;
            this.CodeUsr = codeUsr;
            this.UrlUsr  = urlUsr;
            if (TempData.ContainsKey("objRefugio"))
            {
                String jsonStringRefugio = TempData["objRefugio"].ToString();
                Console.WriteLine("JSON STRING: " + jsonStringRefugio);
                Refugio obj = JsonSerializer.Deserialize <Refugio>(jsonStringRefugio);
                Console.WriteLine(obj.Email + "  " + obj.Direccion);
                await Create(obj);

                Console.WriteLine("Llamé al create");
                var options = new JsonSerializerOptions {
                    WriteIndented = true
                };
                string jsonString = JsonSerializer.Serialize(this.solicitud, options);
                TempData["solicitud"] = jsonString;
                Console.WriteLine("Se guardo el json");

                return(RedirectToAction("IntermediarioCreate", "/SolicitudRefugio"));
                //Console.WriteLine("Se redirecciono y ya se regreso de ahí");
            }
            else
            {
                Console.WriteLine("No contiene valor el TEmpData");
                TempData["FalloCrearRefugio"] = "TRUE";
            }
            return(View());
        }
示例#6
0
        public int ModificarRefugio(Refugio refugio)
        {
            dbConnection.Update(refugio);
            int pk = refugio.IdRefugio.Value;

            return(pk);
        }
示例#7
0
        public async Task <IActionResult> PutRefugio(int id, Refugio refugio)
        {
            if (id != refugio.RefugioId)
            {
                return(BadRequest());
            }

            _context.Entry(refugio).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RefugioExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#8
0
        private async void Registrar_Clicked(object sender, EventArgs e)
        {
            string validacion = ValidarForm();

            if (validacion == "")
            {
                try{
                    var currentPosition = await CrossGeolocator.Current.GetLastKnownLocationAsync();

                    usuario.IdTipoUsuario = 3;
                    int     id      = servicioUsuarios.RegistrarUsuario(usuario);
                    Refugio refugio = new Refugio
                    {
                        RazonSocial   = txtRazonSolial.Text,
                        CodigoPostal  = txtCodigoP.Text,
                        Direccion     = txtDireccion.Text,
                        FechaCreacion = DateTime.UtcNow.ToString("dd-MM-yyyy"),
                        IdRefugio     = null,
                        IdUsuario     = id,
                        Localidad     = txtLocalidad.Text,
                        Telefono      = long.Parse(txtTel.Text),
                        Ubicacion     = currentPosition.Latitude.ToString() + ";" + currentPosition.Longitude.ToString(),
                        Estado        = "Pendiente"
                    };
                    servicioRefugio.RegistrarRefugio(refugio);
                    validacion = "Se realizo el registro con exito, la solicitud se encuentra en estado pendiente. Para continuar con el tramite debera enviar la documentacion que certifique los datos ingresados al mail: [email protected].";
                }catch (Exception ex) {
                    validacion = "Se produjo un problema, vuelva a intentar.";
                }
            }
            await DisplayAlert("Registro Refugio", validacion, "Ok");

            await App.MasterD.Detail.Navigation.PopToRootAsync();
        }
示例#9
0
 public string DeleteRefugioDomainService(int id, Refugio refugio)
 {
     if (refugio == null)
     {
         return("El refugio no existe.");
     }
     return(null);
 }
示例#10
0
 public string PostRefugioDomainService(Refugio refugio)
 {
     if (refugio.nombre == "")
     {
         return("Se necesita el nombre del refugio.");
     }
     return(null);
 }
        public void PruebaParaValidarSiHayNombreRefugio()
        {
            var refugio = new Refugio();

            refugio.nombre = "";

            var refugioDomainService = new RefugioDomainService();
            var resultado            = refugioDomainService.PostRefugioDomainService(refugio);

            Assert.AreEqual("Se necesita el nombre del refugio.", resultado);
        }
示例#12
0
        public int ObtenerRazonSocial(string razon)
        {
            int     i       = -1;
            Refugio refugio = dbConnection.Query <Refugio>("Select * From [Refugio]").Where(x => x.RazonSocial == razon).FirstOrDefault();

            if (refugio != null)
            {
                i = 1;
            }
            return(i);
        }
示例#13
0
 public string PutRefugioDomainService(int id, Refugio refugio)
 {
     if (id != refugio.id)
     {
         return("El refugio no existe.");
     }
     if (refugio.nombre == "")
     {
         return("Se necesita el nombre del refugio.");
     }
     return(null);
 }
示例#14
0
        public async Task <ActionResult <Refugio> > PostRefugio(Refugio refugio)
        {
            var respuestaRefugioAppService = await _refugioAppService.PostRefugioApplicationService(refugio);

            bool noHayErroresEnValidaciones = respuestaRefugioAppService == null;

            if (noHayErroresEnValidaciones)
            {
                return(CreatedAtAction(nameof(GetRefugio), new { id = refugio.id }, refugio));
            }
            return(BadRequest(respuestaRefugioAppService));
        }
 public string PutMascotaDomainService(int id, Mascota mascota, Refugio refugio)
 {
     if (id != mascota.id)
     {
         return("La mascota no existe.");
     }
     if (refugio == null)
     {
         return("El refugio no existe.");
     }
     return(null);
 }
示例#16
0
        public async Task <IActionResult> PutRefugio(int id, Refugio refugio)
        {
            var respuestaRefugioAppService = await _refugioAppService.PutRefugioApplicationService(id, refugio);

            bool noHayErroresEnValidaciones = respuestaRefugioAppService == null;

            if (noHayErroresEnValidaciones)
            {
                return(NoContent());
            }
            return(BadRequest(respuestaRefugioAppService));
        }
        public void PruebaParaValidarSiRefugioExisteParaEliminar()
        {
            var refugio = new Refugio();
            var id      = new int();

            refugio = null;

            var refugioDomainService = new RefugioDomainService();
            var resultado            = refugioDomainService.DeleteRefugioDomainService(id, refugio);

            Assert.AreEqual("El refugio no existe.", resultado);
        }
        public void PruebaParaValidadSiRefugioExiste()
        {
            var mascota = new Mascota();
            var id      = new int();
            var refugio = new Refugio();

            refugio = null;

            var mascotaDomainService = new MascotaDomainService();
            var resultado            = mascotaDomainService.PutMascotaDomainService(id, mascota, refugio);

            Assert.AreEqual("El refugio no existe.", resultado);
        }
        public async Task <string> PutRefugioApplicationService(int id, Refugio refugio)
        {
            var respuestaDomainService = _refugioDomainService.PutRefugioDomainService(id, refugio);

            bool hayErrorDomainService = respuestaDomainService != null;

            if (hayErrorDomainService)
            {
                return(respuestaDomainService);
            }

            _baseDatos.Entry(refugio).State = EntityState.Modified;
            await _baseDatos.SaveChangesAsync();

            return(null);
        }
        public async Task <string> PostRefugioApplicationService(Refugio refugio)
        {
            var respuestaDomainService = _refugioDomainService.PostRefugioDomainService(refugio);

            bool hayErrorDomainService = respuestaDomainService != null;

            if (hayErrorDomainService)
            {
                return(respuestaDomainService);
            }

            _baseDatos.Refugios.Add(refugio);
            await _baseDatos.SaveChangesAsync();

            return(null);
        }
示例#21
0
        public async Task <string> PutMascotaApplicationService(int id, Mascota mascota)
        {
            Refugio refugio = await _baseDatos.Refugios.FirstOrDefaultAsync(q => q.id == mascota.refugioId);

            var respuestaDomainService = _mascotaDomainService.PutMascotaDomainService(id, mascota, refugio);

            bool hayErrorDomainService = respuestaDomainService != null;

            if (hayErrorDomainService)
            {
                return(respuestaDomainService);
            }

            _baseDatos.Entry(mascota).State = EntityState.Modified;
            await _baseDatos.SaveChangesAsync();

            return(null);
        }
        public void CargarElementos(int idRef)
        {
            btnAceptar.Clicked  += btnAceptar_Clicked;
            btnRechazar.Clicked += btnRechazar_Clicked;

            refugio = servicioRefugio.ObtenerRefugio(idRef);
            Usuario usuario = servicioUsuario.ObtenerUsuario(refugio.IdUsuario);

            txtApellido.Text    = usuario.Apellido;
            txtNombre.Text      = usuario.Nombre;
            txtRazonSocial.Text = refugio.RazonSocial;
            txtDireccion.Text   = refugio.Direccion;
            txtCP.Text          = refugio.CodigoPostal;
            txtLocalidad.Text   = refugio.Localidad;
            //txtFecha.Text = refugio.FechaCreacion.ToString("YYYY-MM-DD HH:MM:SS.SSS");
            txtFecha.Text    = refugio.FechaCreacion.ToString();
            txtTelefono.Text = usuario.Telefono.ToString();
            //CargarMapa(refugio.Ubicacion);
            //CargarRefugio(refugio);
        }
示例#23
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            Debug.WriteLine("POST VALORES:  Email:" + Request.Form["Input.Email"]
                            + "  Pass= "******"Input.Password"]);
            if (Request.Form["Refugio"].Equals("TRUE"))
            {
                Input.Email           = Request.Form["Input.Email"];
                Input.Password        = Request.Form["Input.Password"];
                Input.ConfirmPassword = Request.Form["Input.ConfirmPassword"];
            }

            returnUrl ??= Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid || Request.Form["Refugio"].Equals("TRUE"))
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);
                    // Para los refugios, no se les pide confirmación de Email, así que los datos se retornan para futura confirmación
                    if (Request.Form["Refugio"].Equals("TRUE"))
                    {
                        Refugio obj = new Refugio(Request.Form["Nombre"],
                                                  Request.Form["Direccion"], Request.Form["Telefono"], Request.Form["Email"],
                                                  Request.Form["Contrasenia"], Request.Form["Sitio_web"]);

                        var options = new JsonSerializerOptions {
                            WriteIndented = true
                        };
                        string jsonString = JsonSerializer.Serialize(obj, options);

                        TempData["objRefugio"] = jsonString;
                        // Registrar el rol del usuario
                        if (_roleManager != null)
                        {
                            if (!await _roleManager.RoleExistsAsync(ConstRoles.RefugioRole))
                            {
                                await _roleManager.CreateAsync(new IdentityRole(ConstRoles.RefugioRole));
                            }
                            await _userManager.AddToRoleAsync(user, ConstRoles.RefugioRole);
                        }
                        else
                        {
                            Console.WriteLine("RolMANAGER nulo");
                        }

                        return(RedirectToAction("EnvioDatos", "/Refugios",
                                                new{ IdUsr = user.Id, codeUsr = code, urlUsr = returnUrl }));
                    }
                    // Registrar el rol del usuario Adoptante
                    if (_roleManager != null)
                    {
                        if (!await _roleManager.RoleExistsAsync(ConstRoles.AdoptanteRole))
                        {
                            await _roleManager.CreateAsync(new IdentityRole(ConstRoles.AdoptanteRole));
                        }
                        await _userManager.AddToRoleAsync(user, ConstRoles.AdoptanteRole);
                    }
                    else
                    {
                        Console.WriteLine("RolMANAGER nulo");
                    }
                    // Añadir un registro
                    var        crearAdoptante = Url.Action("IntermediarioCreate", "/Adoptantes", new{ emailUsuario = Input.Email }, Request.Scheme);
                    HttpClient req            = new HttpClient();
                    var        content        = await req.GetAsync(crearAdoptante);

                    Console.WriteLine(await content.Content.ReadAsStringAsync());

                    //
                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }