// // GET: /Crm/VisitRecord/Create public ActionResult Create() { var model = new VisitRecord(); this.RenderMyViewData(model); return View("Edit", model); }
public ActionResult Create(FormCollection collection) { var model = new VisitRecord(); this.TryUpdateModel<VisitRecord>(model); model.CreateTime = model.VisitTime = DateTime.Now; model.Username = this.UserContext.LoginInfo.LoginName; model.UserId = this.UserContext.LoginInfo.UserID; try { this.CrmService.SaveVisitRecord(model); } catch (BusinessException e) { this.ModelState.AddModelError(e.Name, e.Message); this.RenderMyViewData(model); return View("Edit", model); } return this.RefreshParent(); }
private void RenderMyViewData(VisitRecord model, bool isBasic = false) { ViewData.Add("VisitWay", new SelectList(EnumHelper.GetItemValueList<EnumVisitWay>(), "Key", "Value", model.VisitWay)); ViewData.Add("FollowLevel", new SelectList(EnumHelper.GetItemValueList<EnumFollowLevel>(), "Key", "Value", model.FollowLevel)); ViewData.Add("FollowStep", new SelectList(EnumHelper.GetItemValueList<EnumFollowStep>(), "Key", "Value", model.FollowStep)); ViewData.Add("ProductType", new SelectList(EnumHelper.GetItemValueList<EnumProductType>(), "Key", "Value", model.ProductType)); ViewData.Add("Focus", new SelectList(EnumHelper.GetItemList<EnumFocus>(), "Key", "Value", (EnumFocus)model.Focus)); ViewData.Add("CognitiveChannel", new SelectList(EnumHelper.GetItemList<EnumCognitiveChannel>(), "Key", "Value", (EnumCognitiveChannel)model.CognitiveChannel)); ViewData.Add("PriceResponse", new SelectList(EnumHelper.GetItemValueList<EnumPriceResponse>(), "Key", "Value", model.PriceResponse)); ViewData.Add("AreaDemand", new SelectList(EnumHelper.GetItemValueList<EnumAreaDemand>(), "Key", "Value", model.AreaDemand)); ViewData.Add("Motivation", new SelectList(EnumHelper.GetItemValueList<EnumMotivation>(), "Key", "Value", model.Motivation)); ViewData.Add("ProjectId", new SelectList(this.CrmService.GetProjectList(), "Id", "Name", model.ProjectId)); if (isBasic) return; ViewData.Add("CityId", new SelectList(this.CityDic.Values, "Id", "Name", model.CityId)); if (model.CityId == 0) model.CityId = this.CityDic.First().Key; var areas = this.AreaDic.Values.Where(a => a.CityId == model.CityId); ViewData.Add("AreaId", new SelectList(areas, "Id", "Name", model.AreaId)); var request = new CustomerRequest(); request.Customer.UserId = this.UserContext.LoginInfo.UserID; var customerList = this.CrmService.GetCustomerList(request).ToList(); customerList.ForEach(c => c.Name = string.Format("{0}({1})", c.Name, c.Tel)); ViewData.Add("CustomerId", new SelectList(customerList, "Id", "Name", model.CustomerId)); }
public void SaveVisitRecord(VisitRecord visitRecord) { using (var dbContext = new CrmDbContext()) { if (visitRecord.ID > 0) { dbContext.Update<VisitRecord>(visitRecord); } else { dbContext.Insert<VisitRecord>(visitRecord); } } }