Exemplo n.º 1
0
        public Response ModPaciente([FromBody] PacienteViewModel model)
        {
            Response oR = new Response();

            try
            {
                Models.Paciente oPaciente = db.Paciente.Find(model.Id);

                oPaciente.Nombre = model.Nombre;
                oPaciente.NumeroDeSeguroSocial = model.NumeroDeSeguroSocial;
                oPaciente.CodigoPostal         = model.CodigoPostal;
                oPaciente.Telefono             = model.Telefono;
                oPaciente.CedulaDoctor         = model.CedulaDoctor;

                db.Entry(oPaciente).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                db.SaveChanges();

                oR.Succes = 1;
            }
            catch (Exception ex)
            {
                oR.Succes  = 0;
                oR.Message = ex.Message;
            }
            return(oR);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

            var localU = await db.User.FindAsync(user.Id);

            localU.FirstName = user.FirstName;
            localU.LastName  = user.LastName;
            localU.Email     = user.Email;
            localU.Username  = user.Username;
            localU.Status    = user.Status;
            localU.Rol       = user.Rol;

            //If password is empty then keep the current password
            if (!string.IsNullOrEmpty(user.Password))
            {
                localU.Password = HashPassword(user.Password);
            }

            db.Entry(localU).State = EntityState.Modified;

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

            return(Ok(new { success = 1, message = "User Successfully Updated" }));
        }