public ActionResult Edit(Customer entity) { try { //var cus = db.Customer.Where(x => //x.CorporationName.Trim() == entity.CorporationName.Trim() //|| (!string.IsNullOrEmpty(entity.Tel) && x.Tel.Trim() == entity.Tel.Trim()) //|| (!string.IsNullOrEmpty(entity.MobileTel) && x.MobileTel.Trim() == entity.MobileTel.Trim())); //if (cus != null && cus.Count() > 1) //{ // return Content(string.Format("<script >alert('编辑失败,错误信息:已经存在公司名称为'{0}'的公司或者手机电话信息出现重复!系统不允许公司相关信息重复!');window.history.go( -1 ); </script >", entity.CorporationName.Trim()), "text/html"); //} entity.LastModify = DateTime.Now; db.Entry(entity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { return Content(string.Format("<script >alert('编辑失败,错误信息:{0}');window.history.go( -1 ); </script >", ex.Message), "text/html"); } return Content("<script >alert('编辑成功!');window.opener=null;window.close(); </script >", "text/html"); }
public ActionResult Modify(Customer entity) { try { entity.LastModify = DateTime.Now; db.Entry(entity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { return Json(new { success = false, message = "编辑失败,原因:" + ex.Message }); } return Json(new { success = true }); }
public ActionResult Create(Customer entity) { try { var cus = db.Customer.FirstOrDefault(x => x.CorporationName.Trim() == entity.CorporationName.Trim()); // var cus = db.Customer.FirstOrDefault(x => //x.CorporationName.Trim() == entity.CorporationName.Trim() //|| (!string.IsNullOrEmpty(entity.Tel) && x.Tel.Trim() == entity.Tel.Trim()) //|| (!string.IsNullOrEmpty(entity.MobileTel) && x.MobileTel.Trim() == entity.MobileTel.Trim())); if (cus != null) { if (cus.PoolStatus == 2) { //return Json(new { success = false, message = "此客户在公共池中已存在!" }); return Content("<script >alert('此客户在公共池中已存在!');window.history.go( -1 ); </script >", "text/html"); } if (cus.PoolStatus == 3) { //return Json(new { success = false, message = "此客户在废弃池中已存在!" }); return Content("<script >alert('此客户在废弃池中已存在!');window.history.go( -1 ); </script >", "text/html"); } //return Json(new { success = false, message = string.Format("此客户已存在,所有者为{0}!", cus.User.USERNAME) }); return Content(string.Format("<script >alert('此客户已存在,所有者为{0}!');window.history.go( -1 ); </script >",cus.User.USERNAME), "text/html"); } User user = GetCurrentUser(); entity.Owner = user.USERID; entity.Creator = user.USERID; entity.DepartmentID = user.DEPARTMENTID; entity.PoolStatus = privateTag; entity.CreateDate = DateTime.Now; entity.LastModify = DateTime.Now; entity.BelongDateTime = DateTime.Now; db.Customer.Add(entity); db.SaveChanges(); } catch (Exception ex) { return Content(string.Format("<script >alert('添加客户失败,错误信息:{0}');window.history.go( -1 ); </script >", ex.Message), "text/html"); } return RedirectToAction("Create"); }