コード例 #1
0
        public ActionResult CreateOrUpdateAccount(int?accountId)
        {
            CreateOrUpdateAccountViewModel vm;

            if (accountId == null)
            {
                vm = new CreateOrUpdateAccountViewModel()
                {
                    RankList = _rankService.Read().Select(a => new SelectListItem()
                    {
                        Value = a.Id.ToString(),
                        Text  = a.RankName
                    }).ToList(),
                    EventPricesSource = new List <SelectListItem>()
                    {
                        new SelectListItem()
                        {
                            Value = "0", Text = "0%"
                        },
                        new SelectListItem()
                        {
                            Value = "5", Text = "5%"
                        },
                        new SelectListItem()
                        {
                            Value = "10", Text = "10%"
                        },
                        new SelectListItem()
                        {
                            Value = "15", Text = "15%"
                        },
                        new SelectListItem()
                        {
                            Value = "20", Text = "20%"
                        },
                        new SelectListItem()
                        {
                            Value = "25", Text = "25%"
                        },
                        new SelectListItem()
                        {
                            Value = "30", Text = "30%"
                        },
                        new SelectListItem()
                        {
                            Value = "35", Text = "35%"
                        },
                        new SelectListItem()
                        {
                            Value = "40", Text = "40%"
                        },
                        new SelectListItem()
                        {
                            Value = "45", Text = "45%"
                        },
                        new SelectListItem()
                        {
                            Value = "50", Text = "50%"
                        }
                    },
                    EventPrice = 0
                };
            }
            else
            {
                var accountDto = _accountService.ReadOneById(accountId ?? 0);

                if (accountDto == null)
                {
                    return(HttpNotFound(""));
                }

                vm = new CreateOrUpdateAccountViewModel()
                {
                    RankList = _rankService.Read().Select(a => new SelectListItem()
                    {
                        Value    = a.Id.ToString(),
                        Text     = a.RankName,
                        Selected = (a.Id == accountDto.RankId)
                    }).ToList(),
                    Price             = accountDto.Price,
                    Description       = accountDto.Description,
                    UserName          = accountDto.UserName,
                    Password          = accountDto.Password,
                    RankId            = accountDto.RankId,
                    AccounId          = accountDto.Id,
                    EventPrice        = accountDto.EventPrice,
                    EventPricesSource = new List <SelectListItem>()
                    {
                        new SelectListItem()
                        {
                            Value = "0", Text = "0%", Selected = accountDto.EventPrice == 0
                        },
                        new SelectListItem()
                        {
                            Value = "5", Text = "5%", Selected = accountDto.EventPrice == 5
                        },
                        new SelectListItem()
                        {
                            Value = "10", Text = "10%", Selected = accountDto.EventPrice == 10
                        },
                        new SelectListItem()
                        {
                            Value = "15", Text = "15%", Selected = accountDto.EventPrice == 15
                        },
                        new SelectListItem()
                        {
                            Value = "20", Text = "20%", Selected = accountDto.EventPrice == 20
                        },
                        new SelectListItem()
                        {
                            Value = "25", Text = "25%", Selected = accountDto.EventPrice == 25
                        },
                        new SelectListItem()
                        {
                            Value = "30", Text = "30%", Selected = accountDto.EventPrice == 30
                        },
                        new SelectListItem()
                        {
                            Value = "35", Text = "35%", Selected = accountDto.EventPrice == 35
                        },
                        new SelectListItem()
                        {
                            Value = "40", Text = "40%", Selected = accountDto.EventPrice == 40
                        },
                        new SelectListItem()
                        {
                            Value = "45", Text = "45%", Selected = accountDto.EventPrice == 45
                        },
                        new SelectListItem()
                        {
                            Value = "50", Text = "50%", Selected = accountDto.EventPrice == 50
                        }
                    },
                };
            }

            return(View(vm));
        }
コード例 #2
0
        public ActionResult CreateOrUpdateAccount(CreateOrUpdateAccountViewModel data)
        {
            var        path = Server.MapPath(ConfigurationManager.AppSettings["AvatarUrl"]);
            AccountDto createOrpdateResult;

            if (data.AccounId == 0)
            {
                var result = new AccountDto()
                {
                    UserName    = data.UserName,
                    Password    = data.Password,
                    CreatedDate = DateTime.Now,
                    Description = data.Description,
                    Price       = data.Price,
                    RankId      = data.RankId,
                    Avatar      = ConfigurationManager.AppSettings["AvatarUrl"] + FileUlti.SaveFile(data.Avatar, path),
                    IsAvailable = true,
                    IsHot       = true,
                    EventPrice  = data.EventPrice
                };
                createOrpdateResult = _accountService.Create(result, FileUlti.ReadFromTextFile(data.Champs), FileUlti.ReadFromTextFile(data.Skins));
            }
            else
            {
                var accountDto = _accountService.ReadOneById(data.AccounId);
                var url        = FileUlti.SaveFile(data.Avatar, path);
                accountDto.Price       = data.Price;
                accountDto.Description = data.Description;
                accountDto.Password    = data.Password;
                accountDto.UserName    = data.UserName;
                accountDto.RankId      = data.RankId;
                accountDto.EventPrice  = data.EventPrice;
                accountDto.Avatar      = (!string.IsNullOrEmpty(url) ? accountDto.Avatar : ConfigurationManager.AppSettings["AvatarUrl"] + url);

                if (data.PageGem != null && data.PageGem.All(a => a != null))
                {
                    _accountRelationDataService.DeletePageGemByAccountId(data.AccounId);
                }
                createOrpdateResult = _accountService.Update(accountDto, FileUlti.ReadFromTextFile(data.Champs), FileUlti.ReadFromTextFile(data.Skins));

                if (data.PageGem == null || data.PageGem.Length == 1)
                {
                    return(RedirectToAction("AccountManagement"));
                }
            }

            if (createOrpdateResult != null)
            {
                var pathPageGem = Server.MapPath(ConfigurationManager.AppSettings["PageGemUrl"]);
                if (data.PageGem != null)
                {
                    foreach (var item in data.PageGem)
                    {
                        var pageGem = new PageGemDto()
                        {
                            AccountId   = createOrpdateResult.Id,
                            CreatedDate = DateTime.Now,
                            ImageUrl    = ConfigurationManager.AppSettings["PageGemUrl"] + FileUlti.SaveFile(item, pathPageGem)
                        };

                        _accountRelationDataService.CreatePageGem(pageGem);
                    }
                }
            }
            return(RedirectToAction("AccountManagement"));
        }