public ActionResult Edit(BoxCreateDTO req) { Response res = new Response(); if (ModelState.IsValid) { try { if (req.Id > 0) { res.Data = _boxRepository.Update(req); } else { res.Data = _boxRepository.Create(req); } } catch (Exception ex) { res.Message = ex.Message; } } else { res.Data = false; res.Message = string.Join(",", ModelState .SelectMany(ms => ms.Value.Errors) .Select(e => e.ErrorMessage)); } return(Json(res, JsonRequestBehavior.AllowGet)); }
public bool Update(BoxCreateDTO req) { using (var db = new SqlSugarClient(Connection)) { bool result = true; R_Box model = new R_Box() { Name = req.Name, Description = req.Description, Id = req.Id, R_Restaurant_Id = req.Restaurant, R_Area_Id = req.RestaurantArea }; result = db.Update(model); return(result); } }
public bool Create(BoxCreateDTO req) { using (var db = new SqlSugarClient(Connection)) { bool result = true; R_Box model = new R_Box() { Name = req.Name, Description = req.Description, R_Area_Id = req.RestaurantArea, R_Restaurant_Id = req.Restaurant }; if (db.Insert(model) == null) { result = false; } return(result); } }
public BoxCreateDTO GetModel(int id) { using (var db = new SqlSugarClient(Connection)) { BoxCreateDTO result = null; var model = db.Queryable <R_Box>().InSingle(id); if (model != null) { result = new BoxCreateDTO() { Id = model.Id, Name = model.Name, Description = model.Description, RestaurantArea = model.R_Area_Id, Restaurant = model.R_Restaurant_Id }; } return(result); } }