コード例 #1
0
        //
        // GET: /Crm/Customer/Create

        public ActionResult Create()
        {
            var model = new Customer();

            this.RenderMyViewData(model);

            return View("Edit", model);
        }
コード例 #2
0
        public ActionResult Create(FormCollection collection)
        {
            var model = new Customer();
            this.TryUpdateModel<Customer>(model);

            try
            {
                this.CrmService.SaveCustomer(model);
            }
            catch (BusinessException e)
            {
                this.ModelState.AddModelError(e.Name, e.Message);
                this.RenderMyViewData(model);
                return View("Edit", model);
            }
            

            return this.RefreshParent();
        }
コード例 #3
0
        private void RenderMyViewData(Customer model, bool isBasic = false)
        {
            ViewData.Add("Gender", new SelectList(EnumHelper.GetItemValueList<EnumGender>(), "Key", "Value", model.Gender));
            ViewData.Add("Category", new SelectList(EnumHelper.GetItemValueList<EnumCategory>(), "Key", "Value", model.Category));
            ViewData.Add("Profession", new SelectList(EnumHelper.GetItemValueList<EnumProfession>(), "Key", "Value", model.Profession));
            ViewData.Add("AgeGroup", new SelectList(EnumHelper.GetItemValueList<EnumAgeGroup>(), "Key", "Value", model.AgeGroup));

            if (isBasic)
                return;

            ViewData.Add("UserId", new SelectList(this.AccountService.GetUserList(), "ID", "LoginName", model.UserId));
        }
コード例 #4
0
ファイル: CrmService.cs プロジェクト: EricCode1983/GMS
        public void SaveCustomer(Customer customer)
        {
            using (var dbContext = new CrmDbContext())
            {
                if (customer.ID > 0)
                {
                    if (dbContext.Customers.Any(c => c.Tel == customer.Tel && c.ID != customer.ID))
                        throw new BusinessException("Tel", "已存在此电话的客户!");

                    if (dbContext.Customers.Any(c => c.Number == customer.Number && c.ID != customer.ID))
                        throw new BusinessException("Number", "已存在此编号的客户!");
                    
                    dbContext.Update<Customer>(customer);
                }
                else
                {
                    if (dbContext.Customers.Any(c => c.Tel == customer.Tel))
                        throw new BusinessException("Tel", "已存在此电话的客户!");

                    if (dbContext.Customers.Any(c => c.Number == customer.Number))
                        throw new BusinessException("Number", "已存在此编号的客户!");
                    
                    dbContext.Insert<Customer>(customer);
                }
            }
        }