public JsonResult editDict(Dictionary dict) { using (DBContext db = new DBContext()) { Dictionary oldOne = db.Dictionary.Where(q => q.ID.Equals(dict.ID)).FirstOrDefault(); if (oldOne == null) { dict.CreatorID = UserContext.user.ID; dict.Creator = UserContext.user.DisplayName; db.Dictionary.Add(dict); } else { oldOne.SortOrder = dict.SortOrder; oldOne.Name = dict.Name; //只有子项的值可以修改 if (!string.IsNullOrEmpty(oldOne.ParentCode)) { oldOne.Code = dict.Code; } oldOne.ModifyTime = DateTime.Now; db.Entry(oldOne).State = EntityState.Modified; } db.SaveChanges(); } return Json(new { code = 1, msg = "保存成功" }); }
public JsonResult editNumber(StoreProduct product) { using (DBContext db = new DBContext()) { Store store = UserContext.store; //判断是否已存在相同商品 StoreProduct sameProduct = db.StoreProduct.Where(q => q.ProductID.Equals(product.ProductID) && q.StoreID.Equals(store.ID) && !q.ID.Equals(product.ID)).FirstOrDefault(); if (sameProduct != null) { return Json(new { code = -1, msg = "已存在相同商品" }); } StoreProduct oldOne = db.StoreProduct.Where(q => q.ID.Equals(product.ID)).FirstOrDefault(); if (oldOne == null) { product.ID = StringUtil.UniqueID(); product.StoreID = store.ID; db.StoreProduct.Add(product); } else { oldOne.ProductNumber = product.ProductNumber; oldOne.OnlinePrice = product.OnlinePrice; oldOne.OfflinePrice = product.OfflinePrice; db.Entry(oldOne).State = EntityState.Modified; } db.SaveChanges(); } return Json(new { code = 1, msg = "保存成功" }); }
public JsonResult editCourier(Courier courier) { using (DBContext db = new DBContext()) { Courier oldCourier = db.Courier.Where(q => q.ID.Equals(courier.ID)).FirstOrDefault(); if (oldCourier == null) { Guser user = UserContext.user; Store store = UserContext.store; courier.CreatorID = user.ID; courier.Creator = user.DisplayName; courier.StoreId = store.ID; courier.Status = Status.enable; db.Courier.Add(courier); } else { oldCourier.ModifyTime = DateTime.Now; oldCourier.CourierTel = courier.CourierTel; oldCourier.Status = courier.Status; db.Entry(oldCourier).State = EntityState.Modified; } db.SaveChanges(); } return Json(new { code = 1, msg = "保存成功" }); }
public JsonResult editItem(OrderItem item) { using (DBContext db = new DBContext()) { //判断订单是否存在 Order order = db.Order.Where(q => q.ID.Equals(item.OrderId)).FirstOrDefault(); if (order == null) { return Json(new { code = -1, msg = "找不到对应订单" }); } if (order.Status == OrderStatus.Sended) { return Json(new { code = -2, msg = "订单已发货,无法修改" }); } if (order.Status == OrderStatus.Reject) { return Json(new { code = -3, msg = "订单已被驳回,无法修改" }); } OrderItem oldItem = db.OrderItem.Where(q => q.ID.Equals(item.ID)).FirstOrDefault(); if (oldItem == null) { return Json(new { code = -4, msg = "找不到对应商品" }); } oldItem.Discount = item.Discount; oldItem.RealNumber = item.RealNumber; db.Entry(oldItem).State = EntityState.Modified; db.SaveChanges(); } decimal pay = Order.RefreshPay(item.OrderId); return Json(new { code = 1, msg = "保存成功", pay = pay }); }
public static decimal RefreshPay(string id) { using (DBContext db = new DBContext()) { Order order = db.Order.Where(q => q.ID.Equals(id)).FirstOrDefault(); decimal pay = db.OrderItem.Where(q => q.OrderId.Equals(id)).Sum(q => q.Price * q.RealNumber * q.Discount); order.Payable = pay; order.Paid = pay; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return pay; } }
public JsonResult changePassword(string oldPass, string newPass) { using (DBContext db = new DBContext()) { string _oldPass = StringUtil.Md5Encrypt(oldPass); Guser user = UserContext.user; if (!user.PassWord.Equals(_oldPass)) { return Json(new { code = -1, msg = "原密码错误" }); } user.PassWord = StringUtil.Md5Encrypt(newPass); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return Json(new { code = 1, msg = "修改成功,3秒后跳转到登录页面", url = "Login/LogOff" }); } }
public JsonResult editItem(OrderItem item) { using (DBContext db = new DBContext()) { //判断订单是否存在 Order order = db.Order.Where(q => q.ID.Equals(item.OrderId)).FirstOrDefault(); if (order == null) { return Json(new { code = -1, msg = "找不到对应订单" }); } if (order.Status > OrderStatus.BeforeSubmit && UserContext.store != null) { return Json(new { code = -2, msg = "您没有权限修改已提交过的订单" }); } if (order.Status == OrderStatus.Sended) { return Json(new { code = -3, msg = "订单已发货,无法修改" }); } if (order.Status == OrderStatus.Reject) { return Json(new { code = -4, msg = "订单已被驳回,无法修改" }); } //判断订单中是否已有此样商品 OrderItem sameItem = db.OrderItem.Where(q => q.OrderId.Equals(item.OrderId) && q.ProductId.Equals(item.ProductId) && !q.ID.Equals(item.ID)).FirstOrDefault(); if (sameItem != null) { return Json(new { code = -5, msg = "订单中已有相同商品" }); } OrderItem oldItem = db.OrderItem.Where(q => q.ID.Equals(item.ID)).FirstOrDefault(); if (oldItem == null) { Product product = db.Product.Where(q => q.ID.Equals(item.ProductId)).FirstOrDefault(); if (product == null) { return Json(new { code = -6, msg = "抱歉,找不到对应商品" }); } item.ID = StringUtil.UniqueID(); item.ProductCode = product.ProductCode; item.ProductName = product.ProductName; item.Price = product.Price; item.RealNumber = item.OrderNumber; db.OrderItem.Add(item); } else { oldItem.OrderNumber = item.OrderNumber; oldItem.RealNumber = item.OrderNumber; db.Entry(oldItem).State = EntityState.Modified; } db.SaveChanges(); } Order.RefreshPay(item.OrderId); return Json(new { code = 1, msg = "保存成功" }); }
public JsonResult editNotice(Notice notice) { using (DBContext db = new DBContext()) { //判断标题是否重复 Notice sameTitle = db.Notice.Where(q => q.Title.Equals(notice.Title) && !q.ID.Equals(notice.ID)).FirstOrDefault(); if (sameTitle != null) { return Json(new { code = -1, msg = "已存在相同标题的公告" }); } Notice oldNotice = db.Notice.Where(q => q.ID.Equals(notice.ID)).FirstOrDefault(); if (oldNotice == null) { notice.CreatorID = UserContext.user.ID; notice.Creator = UserContext.user.DisplayName; notice.Status = NoticeStatus.Draft; db.Notice.Add(notice); } else { if (oldNotice.Status == NoticeStatus.Published) { return Json(new { code = -2, msg = "已发布的公告不可以修改" }); } oldNotice.ModifyTime = DateTime.Now; oldNotice.Title = notice.Title; oldNotice.Content = notice.Content; oldNotice.Status = notice.Status; db.Entry(oldNotice).State = EntityState.Modified; } db.SaveChanges(); } return Json(new { code = 1, msg = "保存成功" }); }
public JsonResult editRole(GuserRole role) { using (DBContext db = new DBContext()) { //判断名称是否重复 GuserRole sameName = db.GuserRole.Where(q => q.RoleName.Equals(role.RoleName) && !q.ID.Equals(role.ID)).FirstOrDefault(); if (sameName != null) { return Json(new { code = -1, msg = "已有同名角色" }); } //判断权限值是否重复 GuserRole sameAuth = db.GuserRole.Where(q => q.RoleVal.Equals(role.RoleVal) && !q.ID.Equals(role.ID)).FirstOrDefault(); if (sameAuth != null) { return Json(new { code = -2, msg = "已有相同权限的角色" }); } GuserRole oldRole = db.GuserRole.Where(q => q.ID.Equals(role.ID)).FirstOrDefault(); if (oldRole == null) { role.CreatorID = UserContext.user.ID; role.Creator = UserContext.user.DisplayName; role.Status = Status.enable; db.GuserRole.Add(role); } else { List<Guser> users = db.Guser.Where(q => q.RoleId.Equals(role.ID)).ToList(); if (users.Count > 0 && role.Status == Status.disable) { return Json(new { code = -3, msg = "不能禁用已有用户的角色" }); } oldRole.ModifyTime = DateTime.Now; oldRole.RoleName = role.RoleName; oldRole.RoleVal = role.RoleVal; oldRole.Status = role.Status; db.Entry(oldRole).State = EntityState.Modified; } db.SaveChanges(); } return Json(new { code = 1, msg = "保存成功" }); }
public JsonResult editUser(Guser user) { using (DBContext db = new DBContext()) { //判断编号是否重复 Guser sameAccount = db.Guser.Where(q => q.Account.Equals(user.Account) && !q.ID.Equals(user.ID)).FirstOrDefault(); if (sameAccount != null) { return Json(new { code = -1, msg = "用户编号已被注册" }); } Guser oldUser = db.Guser.Where(q => q.ID.Equals(user.ID)).FirstOrDefault(); if (oldUser == null) { user.CreatorID = UserContext.user.ID; user.Creator = UserContext.user.DisplayName; user.Name = user.DisplayName; user.PassWord = StringUtil.Md5Encrypt("888"); user.Status = Status.enable; db.Guser.Add(user); } else { oldUser.ModifyTime = DateTime.Now; oldUser.CardNumber = user.CardNumber; oldUser.Name = user.DisplayName; oldUser.RoleId = user.RoleId; oldUser.Sex = user.Sex; oldUser.Tel = user.Tel; oldUser.Status = user.Status; db.Entry(oldUser).State = EntityState.Modified; } db.SaveChanges(); } return Json(new { code = 1, msg = "保存成功" }); }
public JsonResult editProduct(Product product) { using (DBContext db = new DBContext()) { //判断编号是否重复 Product sameCode = db.Product.Where(q => q.ProductCode.Equals(product.ProductCode) && !q.ID.Equals(product.ID)).FirstOrDefault(); if (sameCode != null) { return Json(new { code = -1, msg = "商品编号已被注册" }); } Product oldProduct = db.Product.Where(q => q.ID.Equals(product.ID)).FirstOrDefault(); if (oldProduct == null) { product.CreatorID = UserContext.user.ID; product.Creator = UserContext.user.DisplayName; product.Name = product.ProductName; product.Status = Status.enable; product.StoreId = UserContext.store.ID; db.Product.Add(product); } else { if (UserContext.store != null && UserContext.store.ID != oldProduct.StoreId) { return Json(new { code = -2, msg = "抱歉,您没有权限修改本商品" }); } if (!string.IsNullOrEmpty(oldProduct.DocId) && !oldProduct.DocId.Equals(product.DocId)) { string basePath = string.Format(@"{0}Upload\", Server.MapPath("/")); Doc.delete(oldProduct.DocId, basePath); } oldProduct.ModifyTime = DateTime.Now; oldProduct.ProductCode = product.ProductCode; oldProduct.Name = product.ProductName; oldProduct.ProductType = product.ProductType; oldProduct.Price = product.Price; oldProduct.AllowReturn = product.AllowReturn; oldProduct.Remark = product.Remark; oldProduct.DocId = product.DocId; oldProduct.Status = product.Status; db.Entry(oldProduct).State = EntityState.Modified; } db.SaveChanges(); } return Json(new { code = 1, msg = "保存成功" }); }
public JsonResult editStore(Store store) { using (DBContext db = new DBContext()) { //判断店名是否重复 Store sameName = db.Store.Where(q => q.StoreName.Equals(store.StoreName) && !q.ID.Equals(store.ID)).FirstOrDefault(); if (sameName != null) { return Json(new { code = -1, msg = "门店名称已被注册" }); } Store oldStore = db.Store.Where(q => q.ID.Equals(store.ID)).FirstOrDefault(); if (oldStore == null) { //生成流水号 int code = db.Store.Count() == 0 ? 80000 : Convert.ToInt32(db.Store.Max(q => q.StoreCode)) + 1; store.StoreCode = code.ToString(); store.CreatorID = UserContext.user.ID; store.Creator = UserContext.user.DisplayName; store.Name = store.StoreName; store.Status = Status.enable; db.Store.Add(store); } else { oldStore.ModifyTime = DateTime.Now; oldStore.Name = store.StoreName; oldStore.UserId = store.UserId; oldStore.Address = store.Address; oldStore.Lng = store.Lng; oldStore.Lat = store.Lat; oldStore.Presider = store.Presider; oldStore.Tel = store.Tel; oldStore.StoreType = store.StoreType; oldStore.Discount = store.Discount; oldStore.Alipay = store.Alipay; oldStore.WeiXin = store.WeiXin; oldStore.Bank = store.Bank; oldStore.BankName = store.BankName; oldStore.BankAccount = store.BankAccount; oldStore.Status = store.Status; db.Entry(oldStore).State = EntityState.Modified; } db.SaveChanges(); } return Json(new { code = 1, msg = "保存成功" }); }