コード例 #1
0
        // GET: Administration/Cigars/Create
        public IActionResult Create()
        {
            var viewModel = new CreateCigarInputModel
            {
                BrandItems    = this.cigarServiceAdmin.BrandsAsKeyValuePairs(),
                ShapeItems    = this.cigarServiceAdmin.ShapeAsKeyValuePairs(),
                StrenghtItems = this.cigarServiceAdmin.StrengthAsKeyValuePairs(),
                TasteItems    = this.cigarServiceAdmin.TasteAsKeyValuePairs(),
                SizeItems     = this.cigarServiceAdmin.SizeAsKeyValuePairs(),
            };

            return(this.View(viewModel));
        }
コード例 #2
0
        public async Task CreateCigar(CreateCigarInputModel input)
        {
            var cigar = new Cigar
            {
                BrandId      = input.BrandId,
                CigarName    = input.CigarName,
                StrenghtId   = input.StrenghtId,
                TasteId      = input.TasteId,
                SizeId       = input.SizeId,
                Bland        = input.Bland,
                ShapeId      = input.ShapeId,
                PricePerUnit = input.PricePerUnit,
                ImageUrl     = input.ImageUrl,
            };

            await this.cigarRepository.AddAsync(cigar);

            await this.cigarRepository.SaveChangesAsync();
        }
コード例 #3
0
        public async Task <IActionResult> Create(CreateCigarInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                var viewModel = new CreateCigarInputModel
                {
                    BrandItems    = this.cigarServiceAdmin.BrandsAsKeyValuePairs(),
                    ShapeItems    = this.cigarServiceAdmin.ShapeAsKeyValuePairs(),
                    StrenghtItems = this.cigarServiceAdmin.StrengthAsKeyValuePairs(),
                    TasteItems    = this.cigarServiceAdmin.TasteAsKeyValuePairs(),
                    SizeItems     = this.cigarServiceAdmin.SizeAsKeyValuePairs(),
                };

                return(this.View(viewModel));
            }

            await this.cigarServiceAdmin.CreateCigar(input);

            return(this.RedirectToAction(nameof(this.Index)));
        }