//餐厅删除 public ActionResult RestaurantDel(string id) { ServiceReturnMsg srm = new ServiceReturnMsg(); try { if (string.IsNullOrEmpty(id)) { srm.ReturnCode = 0; srm.ReturnMsg = "删除出错:传递参数错误"; return(Json(srm)); } var Id = Guid.Parse(id); Restaurant entity = db.Restaurant.Where(it => it.Id == Id).FirstOrDefault(); db.Entry(entity).State = EntityState.Deleted; int row = db.SaveChanges(); //RestaurantMenu restaurant = new RestaurantMenu() { RestaurantId=Id }; //db.RestaurantMenu.Attach(restaurant); //db.RestaurantMenu.Remove(restaurant); //row = db.SaveChanges(); string strsql = "delete from RestaurantMenu where RestaurantId=@RestaurantId"; SqlParameter[] paras = { new SqlParameter("@RestaurantId", Id) }; db.Database.ExecuteSqlCommand(strsql, paras); db.SaveChanges(); //删除餐厅环境数据 RestaurantEnvInfo envinfo = db.RestaurantEnvInfo.FirstOrDefault(t => t.RestaurantId == entity.RestaurantEnvInfoId); db.Entry(envinfo).State = EntityState.Deleted; db.SaveChanges(); srm.ReturnCode = row > 0 ? 1 : 0; srm.ReturnMsg = row > 0 ? "删除成功!" : "删除失败!"; } catch (Exception ex) { srm.ReturnCode = 0; srm.ReturnMsg = "删除出错," + ex.Message; } return(Json(srm)); }
public ActionResult LoadShopRecord(Guid?id) { ServiceReturnMsg srm = new ServiceReturnMsg(); RestaurantEnvInfo model = new RestaurantEnvInfo(); try { model = db.RestaurantEnvInfo.Find(id); Restaurant resModel = db.Restaurant.FirstOrDefault(t => t.RestaurantEnvInfoId == id); srm.ReturnCode = 1; srm.ReturnData = new { envinfo = model, res = resModel }; } catch (Exception ex) { srm.ReturnCode = 0; srm.ReturnMsg = "查询餐厅基础与环境数据出错," + ex.Message; } return(Json(srm)); }
public ActionResult AddShopRecord(RestaurantEnvInfo model) { ServiceReturnMsg srm = new ServiceReturnMsg(); Restaurant restaurant = new Restaurant(); string rname = Request.Form["RestaurantName"]; string DPId = Request.Form["DPId"]; string MeanPrice = Request.Form["MeanPrice"]; string Address = Request.Form["Address"]; try { if (!ModelState.IsValid) { var msg = string.Empty; foreach (var value in ModelState.Values) { if (value.Errors.Count > 0) { foreach (var error in value.Errors) { //msg = msg + error.ErrorMessage; srm.ReturnCode = 0; srm.ReturnMsg = error.ErrorMessage; return(Json(srm)); } } } } if (ModelState.IsValid) { if (db.Restaurant.FirstOrDefault(r => r.Name == rname) != null) { srm.ReturnCode = 0; srm.ReturnMsg = "该餐厅已存在"; return(Json(srm)); } string fwryxx = Request["服务人员形象"]; string cjts = Request["餐具特色"]; string zm = Request["照明"]; string cdcx = Request["菜单呈现"]; string wsjsn = Request["卫生间室内"]; string wsjxst = Request["卫生间洗手台"]; string wsjzcj = Request["卫生间坐厕间"]; #region 保存餐厅环境数据 model.务人员形象 = SumValue(fwryxx); model.餐具特色 = SumValue(cjts); model.照明 = SumValue(zm); model.菜单呈现 = SumValue(cdcx); model.卫生间室内 = SumValue(wsjsn); model.卫生间洗手台 = SumValue(wsjxst); model.卫生间坐厕间 = SumValue(wsjzcj); string xc = model.新菜 == null ? "" : model.新菜; string dnmj = model.店内面积 == null ? "" : model.店内面积; model.新菜 = xc; model.店内面积 = dnmj; model.RestaurantId = Guid.NewGuid(); db.RestaurantEnvInfo.Add(model); db.SaveChanges(); #endregion //============================================= #region 保存餐厅基础数据 restaurant.Name = rname; restaurant.DPId = DPId; restaurant.MeanPrice = Convert.ToInt32(MeanPrice); restaurant.Address = Address; string UserName = Request.Cookies["UserInfo"].Values["UserName"].ToString(); string UserId = Request.Cookies["UserInfo"].Values["UserId"].ToString(); restaurant.Creator = HttpUtility.UrlDecode(UserName); restaurant.UserId = Convert.ToInt32(UserId); restaurant.Id = Guid.NewGuid(); restaurant.RestaurantEnvInfoId = model.RestaurantId; restaurant.created = DateTime.Now; db.Restaurant.Add(restaurant); int row = db.SaveChanges(); #endregion //============================================= srm.ReturnCode = row > 0 ? 1 : 0; srm.ReturnMsg = row > 0 ? "添加成功!" : "添加失败!"; } } catch (Exception ex) { srm.ReturnCode = 0; srm.ReturnMsg = "添加出错," + ex.Message; } return(Json(srm)); //View(restaurant); }
public ActionResult UpdateShopRecord(RestaurantEnvInfo model) { ServiceReturnMsg srm = new ServiceReturnMsg(); string rname = Request.Form["RestaurantName"]; string DPId = Request.Form["DPId"]; string MeanPrice = Request.Form["MeanPrice"]; string Address = Request.Form["Address"]; Guid resid = Guid.Parse(Request.Form["Resid"]); try { if (!ModelState.IsValid) { var msg = string.Empty; foreach (var value in ModelState.Values) { if (value.Errors.Count > 0) { foreach (var error in value.Errors) { //msg = msg + error.ErrorMessage; srm.ReturnCode = 0; srm.ReturnMsg = error.ErrorMessage; return(Json(srm)); } } } } if (ModelState.IsValid) { Restaurant resEntity = db.Restaurant.FirstOrDefault(t => t.RestaurantEnvInfoId == resid); //RestaurantEnvInfo envInfoEntity = db.RestaurantEnvInfo.FirstOrDefault(t => t.RestaurantId == model.RestaurantId); //保存餐厅环境数据 string fwryxx = Request["服务人员形象"]; string cjts = Request["餐具特色"]; string zm = Request["照明"]; string cdcx = Request["菜单呈现"]; string wsjsn = Request["卫生间室内"]; string wsjxst = Request["卫生间洗手台"]; string wsjzcj = Request["卫生间坐厕间"]; #region 保存餐厅环境数据 model.务人员形象 = SumValue(fwryxx); model.餐具特色 = SumValue(cjts); model.照明 = SumValue(zm); model.菜单呈现 = SumValue(cdcx); model.卫生间室内 = SumValue(wsjsn); model.卫生间洗手台 = SumValue(wsjxst); model.卫生间坐厕间 = SumValue(wsjzcj); string xc = model.新菜 == null ? "" : model.新菜; string dnmj = model.店内面积 == null ? "" : model.店内面积; model.新菜 = xc; model.店内面积 = dnmj; model.RestaurantId = resid; db.Entry(model).State = EntityState.Modified; db.SaveChanges(); #endregion //============================================= #region 保存餐厅基础数据 resEntity.Name = rname; resEntity.DPId = DPId; resEntity.MeanPrice = Convert.ToInt32(MeanPrice); resEntity.Address = Address; resEntity.modified = DateTime.Now; db.Entry(resEntity).State = EntityState.Modified; int row = db.SaveChanges(); #endregion //============================================= srm.ReturnCode = row > 0 ? 1 : 0; srm.ReturnMsg = row > 0 ? "修改成功!" : "修改失败!"; } } catch (Exception ex) { srm.ReturnCode = 0; srm.ReturnMsg = "修改出错," + ex.Message; } return(Json(srm)); }