public object Save(Sys_BasicData entity, int type) { JsonHelp json = new JsonHelp() { Status = "n", Msg = "保存失败" }; entity.TypeId = type; if (!Any(p => p.Id == entity.Id)) { if (Insert(entity)) { json.Status = "y"; json.Msg = "保存成功"; //添加操作日志 DB.SysLogs.setAdminLog("Add", "新建名称为[" + entity.BasicDataName + "]的部门"); } } else { //禁止更新列 var model = DB.Sys_BasicData.FindEntity(entity.Id); WebTools.CopyToObject(entity, model); if (Update(model)) { json.Status = "y"; json.Msg = "保存成功"; //添加操作日志 DB.SysLogs.setAdminLog("Edit", "更新名称为[" + entity.BasicDataName + "]的部门"); } } return(json); }
public JsonHelp Save(Sys_Navigation entity) { JsonHelp json = new JsonHelp() { Status = "n", Msg = "保存失败" }; if (!string.IsNullOrEmpty(entity.action_type)) { entity.action_type = entity.action_type.Trim(','); } if (!Any(p => p.id == entity.id)) { entity.is_sys = 0; entity.nav_type = "System"; if (string.IsNullOrEmpty(entity.parent_id.ToString())) { entity.class_layer = 1; entity.icon = "fa-th-list"; } else { entity.class_layer = 2; } entity.channel_id = 0; if (Insert(entity)) { json.Status = "y"; json.Msg = "保存成功"; DB.CacheRoleId++; //添加操作日志 DB.SysLogs.setAdminLog("Add", "新建名称为[" + entity.title + "]的菜单"); } } else { //禁止更新列 //db.AddDisableUpdateColumn("id", "is_sys", "nav_type", "class_layer", "channel_id", "class_list", "icon");//添加禁止更新列 var model = DB.Sys_Navigation.FindEntity(entity.id); WebTools.CopyToObject(entity, model); if (Update(model)) { json.Status = "y"; json.Msg = "保存成功"; DB.CacheRoleId++; //添加操作日志 DB.SysLogs.setAdminLog("Edit", "更新名称为[" + entity.title + "]的菜单"); } } return(json); }
public ActionResult Save(DataBase.Shop entity) { var json = new JsonHelp(); try { if (entity.ID == 0) { var member = DB.Member_Info.FindEntity(a => a.Code == entity.MemberCode); if (member != null) { entity.MemberID = member.MemberId; entity.NickName = member.NickName; } else { json.Msg = "会员编号不存在"; return(Json(json)); } entity.CreateTime = DateTime.Now; json.IsSuccess = DB.Shop.Insert(entity); json.Msg = "添加"; } else { var old = DB.Shop.FindEntity(entity.ID); entity.IsCheck = old.IsCheck; entity.IsEnable = old.IsEnable; WebTools.CopyToObject(entity, old); json.IsSuccess = DB.Shop.Update(old); json.Msg = "修改"; } if (json.IsSuccess) { json.ReUrl = ControllerPath + "/Index"; //注册成功就跳转到 激活页 json.Msg += "成功"; } else { json.Msg += "失败"; } } catch (Exception e) { json.IsSuccess = false; json.Msg = "操作失败"; LogHelper.Error("保存商家失败:" + WebTools.getFinalException(e)); } return(Json(json)); }
public JsonHelp Save(Sys_Msg entity) { JsonHelp json = new JsonHelp() { Status = "n", Msg = "保存失败" }; var members = DB.Member_Info.Where(a => a.Code == entity.SenderCode || a.Code == entity.ReceiverCode).Select(a => new { a.NickName, a.MemberId, a.Code }).ToList(); var sender = members.FirstOrDefault(a => a.Code == entity.SenderCode); var receiver = members.FirstOrDefault(a => a.Code == entity.ReceiverCode); if (sender == null) { json.Msg = "发送人为空"; return(json); } if (receiver == null) { json.Msg = "接收人为空"; return(json); } entity.SenderId = sender.MemberId; entity.SenderName = sender.NickName; entity.ReceiverId = receiver.MemberId; entity.ReadTime = DateTime.Now; entity.ReceiverName = receiver.NickName; if (entity.MsgId == 0) { entity.State = 0; if (Insert(entity)) { json.Status = "y"; json.Msg = "操作成功"; //添加操作日志 DB.SysLogs.setMemberLog("Save", string.Format("发消息成功,信息id:[{0}],操作成功", entity.MsgId)); } } else { var model = DB.Sys_Msg.FindEntity(entity.MsgId); WebTools.CopyToObject(entity, model); if (Update(entity)) { json.Status = "y"; json.Msg = "操作成功"; //添加操作日志 DB.SysLogs.setMemberLog("Save", string.Format("更新消息成功,信息id:[{0}],操作成功", entity.MsgId)); } } return(json); }
public ActionResult Save(DataBase.Shop entity) { var json = new JsonHelp(); try { if (entity.ID == 0) { entity.MemberID = CurrentUser.Id; entity.NickName = CurrentUser.Name; entity.MemberCode = CurrentUser.LoginName; entity.CreateTime = DateTime.Now; json.IsSuccess = DB.Shop.Insert(entity); } else { var model = DB.Shop.FindEntity(entity.ID); WebTools.CopyToObject(entity, model); entity.CheckTime = DateTime.Now; entity.IsCheck = true; json.IsSuccess = DB.Shop.Update(model); } if (json.IsSuccess) { //json.ReUrl = ControllerPath + "/Index"; //注册成功就跳转到 激活页 json.Msg = "保存成功"; } else { json.Msg = "保存失败"; } } catch (Exception e) { json.IsSuccess = false; json.Msg = "操作失败"; LogHelper.Error("保存商家失败:" + WebTools.getFinalException(e)); } return(Json(json)); }
public ActionResult Save(ShopProduct entity) { var json = new JsonHelp(); //var shangpin = DB.ShopProductCategory.FindEntity(p => p.ID == entity.CategoryID1); var shop = DB.Shop.FindEntity(p => p.ID == 1); entity.UpdateTime = DateTime.Now; var imgs1 = Request["imgpath1"]; var imgs2 = Request["imgpath2"]; try { using (var db = new DbMallEntities()) { if (entity.ID == 0) { // entity.PriceCongXiao = 0; //if (entity.CategoryID1 == ShopEnum.ShopType.订单商品.GetHashCode()) //{ // entity.PriceScore = 0; // entity.PriceVip = 0; //} if (shop == null) { json.IsSuccess = false; json.Msg = "添加失败,您暂无商家权限"; return(Json(json)); } else if (shop.IsCheck != true) { json.IsSuccess = false; json.Msg = "添加失败,您暂无商家权限"; return(Json(json)); } //if (shangpin.Name == "优选区") //{ // if (entity.PriceShopping < 1) // { // json.IsSuccess = false; // json.Msg = "添加失败,现金价不准为0"; // return Json(json); // } // if (entity.PV < 1) // { // json.IsSuccess = false; // json.Msg = "添加失败,积分价不准为0"; // return Json(json); // } //} //else if (shangpin.Name == "消费区") //{ // if (entity.PriceShopping < 1) // { // json.IsSuccess = false; // json.Msg = "添加失败,现金价不准为0"; // return Json(json); // } // if (entity.PV > 1) // { // json.IsSuccess = false; // json.Msg = "添加失败,积分不需要填写"; // return Json(json); // } //} db.ShopProducts.Add(entity); db.SaveChanges(); #region 添加商品相册图片 if (!string.IsNullOrEmpty(imgs1) && imgs1.EndsWith("&")) { var list1 = imgs1.Substring(0, imgs1.Length - 1).Split('&'); var list2 = imgs2.Substring(0, imgs2.Length - 1).Split('&'); if (list1.Length == list2.Length) { var xlist = new List <ShopProductImage>(); for (int i = 0; i < list1.Length; i++) { var img = new ShopProductImage() { CreateTime = DateTime.Now, ProductID = entity.ID, Sort = i + 1, URL = list1[i], ThumURL = list2[i] }; db.ShopProductImages.Add(img); } var first = db.ShopProducts.FirstOrDefault(a => a.ID == entity.ID); first.Image = list1[0]; } else { json.IsSuccess = false; json.Msg = "添加失败,请重试商品图片"; return(Json(json)); } } #endregion json.Msg = "添加"; } else { var first = db.ShopProducts.FirstOrDefault(a => a.ID == entity.ID); WebTools.CopyToObject(entity, first); //json.IsSuccess = DB.ShopProduct.Update(first); #region 修改商品相册图片 //if (json.IsSuccess) { if (!string.IsNullOrEmpty(imgs1) && imgs1.EndsWith("&")) { var list1 = imgs1.Substring(0, imgs1.Length - 1).Split('&'); var list2 = imgs2.Substring(0, imgs2.Length - 1).Split('&'); if (list1.Length == list2.Length) { var olds = db.ShopProductImages.Where(a => a.ProductID == entity.ID); #region 先删除多余的图片 foreach (var item in olds) { var exsit = list1.Any(a => a == item.URL); if (exsit == false) { db.ShopProductImages.Remove(item); } } #endregion #region 再添加原来没有的 for (int i = 0; i < list1.Length; i++) { var cururl = list1[i]; var exsit = olds.FirstOrDefault(a => a.URL == cururl); if (exsit == null) { var img = new ShopProductImage() { CreateTime = DateTime.Now, ProductID = entity.ID, Sort = i + 1, URL = list1[i], ThumURL = list2[i] }; db.ShopProductImages.Add(img); } } #endregion if (list1.Length > 0) { first.Image = list1[0]; } } else { json.IsSuccess = false; } } } #endregion json.Msg = "修改"; } db.SaveChanges(); json.IsSuccess = true; } } catch (Exception e) { json.IsSuccess = false; LogHelper.Error("商品添加失败:" + WebTools.getFinalException(e)); } if (json.IsSuccess) { json.ReUrl = ControllerPath + "/Index"; //注册成功就跳转到 激活页 json.Msg += "成功"; } else { json.Msg += "失败"; } return(Json(json)); }