コード例 #1
0
        public ActionResult AddShop(int?id, string IsEdit)
        {
            if (IsEdit == "1")
            {
                var shop = shopRepository.GetByDatabaseID(id.Value);
                ViewBag.IsEdit = "1";
            }
            ViewBag.TypeList = shopTypeRepositories.GetAll().ToList().Select(p => new SelectListItem
            {
                Text  = p.Name,
                Value = p.ID.ToString(),
            });
            ViewBag.ShopCountLevelList = this.ShopCountLevelRepository.GetAll().ToList().Select(p => new SelectListItem
            {
                Text  = p.CountLevel,
                Value = p.ID.ToString(),
            });
            ViewBag.ShopDifficultLevelList = this.ShopDifficultyLevelRepository.GetAll().ToList().Select(p => new SelectListItem
            {
                Text  = p.ShopDifficultyLevelName,
                Value = p.ID.ToString(),
            });
            UserRepository UserRepo = new UserRepository();
            IEnumerable <SelectListItem> ListSaleUser = UserRepo.GetData(this.Users().DepartMent.ID, Convert.ToInt32(UserEnmType.Sale))
                                                        .Select(p => new SelectListItem
            {
                Text  = p.userName,
                Value = p.ID.ToString().Trim(),
            });

            //IEnumerable<SelectListItem> ListSaleUser = UserRepo.GetAll()
            //    .Where(p=>p.Type.ID==2) //销售
            //    .Select(p => new SelectListItem
            //{
            //    Text = p.userName,
            //    Value = p.ID.ToString().Trim(),
            //});
            ViewData["ListSaleUser"] = ListSaleUser;

            IEnumerable <SelectListItem> listKfUser = UserRepo.GetData(this.Users().DepartMent.ID, Convert.ToInt32(UserEnmType.Person))
                                                      .Select(p => new SelectListItem
            {
                Text  = p.userName,
                Value = p.ID.ToString().Trim(),
            });

            ViewData["listKfUser"] = listKfUser;


            Kf_DepartMentRepository      kf_DepartRepo  = new Kf_DepartMentRepository();
            IEnumerable <SelectListItem> listDepartMent = kf_DepartRepo.GetData(this.Users().DepartMent.ID)
                                                          .Select(p => new SelectListItem
            {
                Text  = p.DepartMentName,
                Value = p.ID.ToString().Trim(),
            });

            ViewData["listDepartMent"] = listDepartMent;

            PayCircleRepository          PayCircleRepo = new PayCircleRepository();
            IEnumerable <SelectListItem> listPayCircle = PayCircleRepo.GetAll().Select(p => new SelectListItem
            {
                Text  = p.PayCircleName,
                Value = p.ID.ToString().Trim(),
            });

            ViewData["listPayCircle"] = listPayCircle;


            IEnumerable <SelectListItem> listDepart = this.kf_DepartMentRepo.GetAll().Select(p => new SelectListItem
            {
                Text  = p.DepartMentName,
                Value = p.ID.ToString().Trim(),
            });

            ViewData["listDepart"] = listDepart;

            if (id != null)
            {
                var shop = shopRepository.GetByDatabaseID(id.Value);
                ViewBag.Edit    = "1";
                shop.TotalScore = 0;
                return(View(shop));
            }
            return(View());
        }
コード例 #2
0
        public ActionResult AddShop(FormCollection collection, string alertMessage, string IsEdit, int?id, string _User)
        {
            Shop _shop = new Shop();

            ViewBag.TypeList = shopTypeRepositories.GetAll().ToList().Select(p => new SelectListItem
            {
                Text  = p.Name,
                Value = p.ID.ToString(),
            });
            //ViewBag.ShopCountLevelList = this.ShopCountLevelRepository.GetAll().ToList().Select(p => new SelectListItem
            //{
            //    Text = p.CountLevel,
            //    Value = p.ID.ToString(),
            //});
            //ViewBag.ShopDifficultLevelList = this.ShopDifficultyLevelRepository.GetAll().ToList().Select(p => new SelectListItem
            //{
            //    Text = p.ShopDifficultyLevelName,
            //    Value =p.ID.ToString(),
            //});
            UserRepository UserRepo = new UserRepository();
            IEnumerable <SelectListItem> ListUser = UserRepo.GetAll().Select(p => new SelectListItem
            {
                Text  = p.userName,
                Value = p.ID.ToString().Trim(),
            });

            ViewData["listUser"] = ListUser;

            PayCircleRepository          PayCircleRepo = new PayCircleRepository();
            IEnumerable <SelectListItem> listPayCircle = PayCircleRepo.GetAll().Select(p => new SelectListItem
            {
                Text  = p.PayCircleName,
                Value = p.ID.ToString().Trim(),
            });

            ViewData["listPayCircle"] = listPayCircle;

            Kf_DepartMentRepository      kf_DepartRepo  = new Kf_DepartMentRepository();
            IEnumerable <SelectListItem> listDepartMent = kf_DepartRepo.GetData(this.Users().DepartMent.ID)
                                                          .Select(p => new SelectListItem
            {
                Text  = p.DepartMentName,
                Value = p.ID.ToString().Trim(),
            });

            ViewData["listDepartMent"] = listDepartMent;

            try
            {
                if (IsEdit == "1")
                {
                    var shopEdit = shopRepository.GetByDatabaseID(id.Value);

                    TryUpdateModel(shopEdit, collection);
                    shopRepository.Update(shopEdit);
                }
                else
                {
                    TryUpdateModel(_shop, collection);
                    if (shopRepository.ExistShopName(_shop.Name))
                    {
                        alertMessage = "添加失败 店铺已存在!";
                        return(View(_shop));
                    }
                    if (_shop.Name.IsNullOrEmpty())
                    {
                        alertMessage = "店铺名不能为空!";
                        return(View(_shop));
                    }
                    //_shop._User = shopRepository.GetUserByuserName(_User);
                    //_shop.TotalScore = _shop.DifficutyLevel.ID + _shop.ShopCountLevel.ID;

                    //_shop._PayCircle = PayCircleRepo.GetByDatabaseID(Convert.ToInt32(collection["_PayCircle"]));
                    //_shop._Kf_DepartMent = this.kf_DepartMentRepo.GetByDatabaseID(Convert.ToInt32(collection["_Kf_DepartMent"]));
                    //_shop.DemandUser = this.UserRepository.GetByDatabaseID(Convert.ToInt32(collection["DemandUser"]));
                    //_shop.SaleUser = UserRepository.GetByDatabaseID(Convert.ToInt32(collection["SaleUser"]));
                    //_shop.MainKfUser = UserRepository.GetByDatabaseID(Convert.ToInt32(collection["MainKfUser"]));
                    //_shop._Kf_DepartMent = this.kf_DepartMentRepo.GetByDatabaseID(Convert.ToInt32(collection["_Kf_DepartMent"]));
                    shopRepository.Save(_shop);
                }

                alertMessage             = "操作成功!";
                ViewData["alertMessage"] = alertMessage;
                return(RedirectToAction("ShopIndex"));
            }
            catch (RuleException ex)
            {
                throw new RuleException(ex.Message, ex);
            }
        }