public async Task <IActionResult> Delete(int id)
        {
            var user = await this.userManager.GetUserAsync(User);

            var animal = await this.animals.ByUserAsync(id, user);

            var isInAdminRole = await this.userManager.IsInRoleAsync(user, WebConstants.AdministratorRole);

            if (isInAdminRole)
            {
                animal = await this.animals.ByIdAsync(id);
            }

            if (animal == null)
            {
                return(this.AccessDenied());
            }

            var model = new DeleteAnimalViewModel
            {
                Id   = animal.Id,
                Name = animal.Name
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public Reply eliminarAnimal([FromBody] DeleteAnimalViewModel model)
        {
            Reply oReply = new Reply();

            oReply.result = 0;

            if (!ModelState.IsValid)
            {
                oReply.message = "No se estan enviando bien los datos";
                return(oReply);
            }

            if (!verificarToken(model.Token))
            {
                oReply.message = "Usuario no autorizado";
                return(oReply);
            }

            using (var db = new mvcApiEntities())
            {
                var oAnimal = db.animal.Find(model.Id);
                oAnimal.idState         = 2;
                db.Entry(oAnimal).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();


                oReply.data    = obtenerLista(db);
                oReply.message = "El Animal " + model.Id + " fue eliminado con exito";
                oReply.result  = 1;
            }

            return(oReply);
        }