public ActionResult Edit(int id, FormCollection collection) { Client s = db.Clients.Find(id); if (s == null) { s = new Client(); db.Clients.Add(s); } //collection.Remove(""); TryUpdateModel(s, "", new string[] { }, new string[] { "" }, collection); if (!UserInfo.CurUser.HasRight("租赁管理-客户维护")) return Redirect("~/content/AccessDeny.htm"); if (ModelState.IsValid) { db.SaveChanges(); if (id == 0) { BLL.Utilities.AddLogAndSave(s.Id, Client.LogClass, "创建", ""); } else { BLL.Utilities.AddLogAndSave(s.Id, Client.LogClass, "修改", ""); } return Redirect("../View/" + s.Id); } return View(s); }
public ActionResult Edit(int id) { Client s = db.Clients.Find(id); if (s == null) { s = new Client(); } if (!UserInfo.CurUser.HasRight("租赁管理-客户维护")) return Redirect("~/content/AccessDeny.htm"); return View(s); }
public ActionResult ChangePassword(int id) { Client s = new Client(); return View(s); }
public ActionResult Create(int projectid, int type, FormCollection collection) { ViewBag.QuDao = DictionaryBLL.GetL2ByName("渠道类型", true); ViewBag.HasAppointment = false; ViewBag.Type = type; bool HasAppointment = (collection["HasAppointment"] != null && collection["HasAppointment"].Equals("Add")) ? true : false; ViewBag.HasAppointment = HasAppointment; ClientCreate cc = new ClientCreate(); cc.ProjectId = projectid; Project p = Project.Get(projectid); if (p.RoomTypes.Count > 0) { cc.RoomType = p.RoomTypes[0].Name; } switch (type) { case 1: cc.GroupId = UserInfo.CurUser.GetGroup(projectid); ViewBag.Msg = "来电客户登记"; break; case 2: ViewBag.Msg = "直访客户登记";//直访客户要选择小组 if (!UserInfo.CurUser.HasRight("客户管理-前台"))//非前台不能做来访登记 { return Redirect("~/content/AccessDeny.htm"); } break; case 3: cc.GroupId = UserInfo.CurUser.GetGroup(projectid); ViewBag.HasAppointment = true; ViewBag.QuDao = new List<Dictionary2> { new Dictionary2 {L1 = "中介", L2=new List<string>()} }; ViewBag.Msg = "中介邀约客户报备"; break; case 4: cc.GroupId = Project.GetGroupByName(projectid, "前台"); ViewBag.HasAppointment = true; ViewBag.QuDao = new List<Dictionary2> { new Dictionary2 {L1 = "电话中心", L2=new List<string>()} }; ViewBag.Msg = "电话中心客户报备"; //ToDo:如果邀约客户未到访,然后再次报备如何处理? break; case 5: cc.GroupId = UserInfo.CurUser.GetGroup(projectid); ViewBag.HasAppointment = true; ViewBag.QuDao = new List<Dictionary2> { new Dictionary2 {L1 = "销售员拓客", L2=new List<string>()} }; ViewBag.Msg = "销售员拓客报备"; break; } ClientStateEnum state = ClientStateEnum.邀约客户; TryUpdateModel(cc, collection); switch (type) { case 1: state = ClientStateEnum.来电客户; if (cc.AppointmentPlanTime != null || cc.AppointmentType != null) { if (cc.AppointmentPlanTime == null) { ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间"); } if (cc.AppointmentType == null) { ModelState.AddModelError("AppointmentType", "请输入邀约类型"); } } break; case 2: state = ClientStateEnum.来访客户; if (cc.AppointmentPlanTime != null || cc.AppointmentType != null) { if (cc.AppointmentPlanTime == null) { ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间"); } if (cc.AppointmentType == null) { ModelState.AddModelError("AppointmentType", "请输入邀约类型"); } } break; case 3: state = ClientStateEnum.邀约客户; if (cc.AppointmentPlanTime == null) { ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间"); } if (cc.AppointmentType == null) { ModelState.AddModelError("AppointmentType", "请输入邀约类型"); } break; case 4: state = ClientStateEnum.邀约客户; if (cc.AppointmentPlanTime == null) { ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间"); } if (cc.AppointmentType == null) { ModelState.AddModelError("AppointmentType", "请输入邀约类型"); } if (string.IsNullOrEmpty(cc.CallPerson)) { ModelState.AddModelError("CallPerson", "请输入经办人"); } break; case 5: state = ClientStateEnum.邀约客户; if (cc.AppointmentPlanTime == null) { ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间"); } if (cc.AppointmentType == null) { ModelState.AddModelError("AppointmentType", "请输入邀约类型"); } break; } Client checkClient = new Client { Id = cc.Id, ProjectId = cc.ProjectId, Phone1 = cc.Phone1, Phone2 = cc.Phone2 }; JsonResult numcheck = PhoneCheck(checkClient.Phone1); Result result = (Result)numcheck.Data; if (!result.success) { if (result.obj.Equals("号码格式错误")) ModelState.AddModelError("Phone1", result.obj.ToString()); } if (!string.IsNullOrEmpty(checkClient.Phone2)) { numcheck = PhoneCheck(checkClient.Phone2); result = (Result)numcheck.Data; if (!result.success) { if (result.obj.Equals("号码格式错误")) ModelState.AddModelError("Phone2", result.obj.ToString()); } } int check = CheckClientByPhone(checkClient); if (check != 0) { ModelState.AddModelError("", "同电话号码客户已经存在,所在组为:" + DepartmentBLL.GetNameById(check)); } if (ModelState.IsValid) { Client c = new Client(); UpdateModel(c, collection); c.ProjectId = cc.ProjectId; c.GroupId = cc.GroupId; c.CreateTime = DateTime.Now; c.StateDate = DateTime.Today; c.State = state; c.CallPerson = cc.CallPerson; db.Clients.Add(c); db.SaveChanges(); ClientActivity ca = new ClientActivity { Person = UserInfo.CurUser.Id }; ca.ClientId = c.Id; switch (type) { case 1: db.ClientActivities.Add(ca); ca.ActualTime = DateTime.Today; ca.Type = "来电"; ca.FirstType = 1; break; case 2: db.ClientActivities.Add(ca); ca.ActualTime = DateTime.Today; ca.Type = "来访"; ca.FirstType = 2; break; case 3: case 4: break; } if (cc.AppointmentType != null) { ClientActivity appoint = new ClientActivity { Person = UserInfo.CurUser.Id }; appoint.ClientId = c.Id; appoint.PlanTime = cc.AppointmentPlanTime; appoint.Type = cc.AppointmentType; appoint.Detail = cc.AppointmentDetail; db.ClientActivities.Add(appoint); } if (!string.IsNullOrEmpty(c.Phone2)) c.AllPhone = string.Format("{0},{1}", c.Phone1, c.Phone2); else c.AllPhone = c.Phone1; Utilities.AddLog(db, c.Id, Client.LogClass, "客户登记", string.Format("{0} 姓名:{1} 电话:{2}", ca.Type ?? cc.AppointmentType, c.Name, c.AllPhone)); c.Code = p.GetNewClientCode(db); db.SaveChanges(); return Redirect("./View/" + c.Id); //ToDo:这个地方有BUG,提交不成功后出错 } else { return View("Create", cc); } }
//检查是否重复 /// <summary> /// /// </summary> /// <param name="c"></param> /// <returns>同电话的组</returns> public int CheckClientByPhone(Client c) { int check = 0; var query = (from o in db.Clients where o.ProjectId == c.ProjectId && o.Id != c.Id && (o.Phone1 == c.Phone1 || (o.Phone2 != null && o.Phone2 == c.Phone1)) select o).FirstOrDefault(); if (query != null) { return query.GroupId; } if (!string.IsNullOrEmpty(c.Phone2)) { var query2 = (from o in db.Clients where o.ProjectId == c.ProjectId && o.Id != c.Id && (o.Phone1 == c.Phone2 || (o.Phone2 != null && o.Phone2 == c.Phone2)) select o).FirstOrDefault(); if (query2 != null) { return query2.GroupId; } } return 0; }