public IHttpActionResult UpdateUser(Models.ModelRequest.Users user) { using (Models.NJFOODEntities db = new Models.NJFOODEntities()) { try { Models.USERS _user = new Models.USERS(); _user = db.USERS.FirstOrDefault(u => u.U_Nick == user.U_Nick && u.U_Email != user.U_Email); if (_user != null) { return(BadRequest("Ya existe un usuario con este Alias")); } _user = db.USERS.FirstOrDefault(u => u.U_Id == user.U_Id); _user.U_Name = user.U_Name; _user.U_Apellidos = user.U_Apellidos; _user.U_Nick = user.U_Nick; _user.U_Email = user.U_Email; _user.U_Pass = user.U_Pass; _user.U_Gender = user.U_Gender; db.Entry(_user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (Exception) { return(BadRequest("Ha ocurrido un error al actualizar el usuario")); } } return(Ok("Usuario actualizado Satisfactoriamente")); }
public IHttpActionResult updateFood(Models.ModelRequest.Food food) { try { using (Models.NJFOODEntities db = new Models.NJFOODEntities()) { Models.FOOD dbFood = new Models.FOOD(); dbFood = db.FOOD.FirstOrDefault(u => u.id == food.id); if (dbFood == null) { return(NotFound()); } dbFood.name = food.name; dbFood.price = food.price; dbFood.description = food.description; dbFood.status = food.status; db.Entry(dbFood).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(Ok("Registro actualizado satisfactoriamente")); } catch (Exception) { return(BadRequest("Ocurrió un error al conectarse al servidor")); } }
public IHttpActionResult ChangeTheStatusOfTheUser(int id) { using (Models.NJFOODEntities db = new Models.NJFOODEntities()) { try { Models.USERS _user = new Models.USERS(); _user = db.USERS.FirstOrDefault(u => u.U_Id == id); if (_user == null) { return(NotFound()); } _user.U_Status = (_user.U_Status == "A") ? "I" : "A"; db.Entry(_user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (Exception) { return(BadRequest("Ha ocurrido un error al cambiar de estado")); } } return(Ok("OK")); }