コード例 #1
0
        public async Task <IActionResult> Create([Bind("Brand,Model,Code,ItemTypeId,ColorId,Price,Quantity")] ItemCreateBindingModel item)
        {
            if (ModelState.IsValid)
            {
                //var currentItem = new Item()
                //{
                //    Brand = item.Brand,
                //    Model = item.Model,
                //    Code = item.Code,
                //    ItemTypeId = item.ItemTypeId,
                //    ColorId = item.ColorId,
                //    Quantity = item.Quantity,
                //    Price = item.Price
                //};

                var currentItem = mapper.Map <Item>(item);

                await service.CreateItemAsync(currentItem);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ColorId"]    = new SelectList(service.GetAllItemColorsAsync().Result, "Id", "Name", item.ColorId);
            ViewData["ItemTypeId"] = new SelectList(service.GetAllItemTypesAsync().Result, "Id", "Name", item.ItemTypeId);
            return(View(item));
        }
コード例 #2
0
        public async Task <IActionResult> Create(ItemCreateBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                model.SubCategories = await this.GetAllCategoriesWithSubCategoriesAsync();

                return(this.View(model));
            }

            var serviceModel = Mapper.Map <ItemCreateServiceModel>(model);

            serviceModel.StartTime = serviceModel.StartTime.ToUniversalTime();
            serviceModel.EndTime   = serviceModel.EndTime.ToUniversalTime();
            serviceModel.UserName  = this.User.Identity.Name;

            var id = await this.itemsService.CreateAsync(serviceModel);

            if (id == null)
            {
                this.ShowErrorMessage(NotificationMessages.ItemCreateError);

                model.SubCategories = await this.GetAllCategoriesWithSubCategoriesAsync();

                return(this.View(model));
            }

            this.ShowSuccessMessage(NotificationMessages.ItemCreated);

            return(this.RedirectToAction("Details", new { id }));
        }
コード例 #3
0
        public async Task <IActionResult> Create()
        {
            var model = new ItemCreateBindingModel
            {
                SubCategories = await this.GetAllCategoriesWithSubCategoriesAsync()
            };

            return(this.View(model));
        }