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 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 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")); }
public IHttpActionResult addFood(Models.ModelRequest.Food food) { try { using (Models.NJFOODEntities db = new Models.NJFOODEntities()) { Models.CATEGORY_FOOD category = new Models.CATEGORY_FOOD(); category = db.CATEGORY_FOOD.FirstOrDefault(u => u.id == food.category); if (category == null) { return(NotFound()); } Models.FOOD dbFood = new Models.FOOD { id = 0, name = food.name, description = food.description, price = food.price, img = "", status = "A", CATEGORY_FOOD = category }; db.FOOD.Add(dbFood); db.SaveChanges(); return(Ok("Comida agregada Satisfactoriamente")); } } catch (Exception) { return(BadRequest("Ha ocurrido un error al agregar la comida")); throw; } }
public IHttpActionResult AddUser(Models.ModelRequest.Users user) { using (Models.NJFOODEntities db = new Models.NJFOODEntities()) { try { if (user.U_Name != null) { Models.USERS _User = new Models.USERS { U_Id = 0, U_Name = user.U_Name, U_Apellidos = user.U_Apellidos, U_Nick = user.U_Nick, U_Email = user.U_Email, U_Pass = user.U_Pass, U_Gender = user.U_Gender }; _User.U_Status = "A"; db.USERS.Add(_User); db.SaveChanges(); } else { return(BadRequest("Debe completar los datos para finalizar el registro")); } } catch (Exception) { return(BadRequest("No se puedo insertar el registro")); } } return(Ok("OK")); }