コード例 #1
0
        public ActionResult Create(ManufacturerFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", viewModel));
            }

            _sqlDbService.InsertManufacturer(viewModel.Name);

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id)
        {
            bool isManufacturerExistingById = await this.manufacturerService.IsManufacturerExistingById(id, false);

            if (!isManufacturerExistingById)
            {
                TempData.AddErrorMessage(string.Format(EntityNotFound, ManufacturerEntity));

                return(this.RedirectToManufacturersIndex(false));
            }

            ManufacturerBasicServiceModel manufacturer = await this.managerManufacturerService.GetEditModelAsync(id);

            ManufacturerFormViewModel model = Mapper.Map <ManufacturerFormViewModel>(manufacturer);

            return(View(model));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, ManufacturerFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            bool isManufacturerExistingById = await this.manufacturerService.IsManufacturerExistingById(id, false);

            if (!isManufacturerExistingById)
            {
                TempData.AddErrorMessage(string.Format(EntityNotFound, ManufacturerEntity));

                return(this.RedirectToManufacturersIndex(false));
            }

            bool isManufacturerModified = await this.managerManufacturerService.IsManufacturerModified(id, model.Name, model.Address);

            if (!isManufacturerModified)
            {
                TempData.AddWarningMessage(EntityNotModified);

                return(View(model));
            }

            bool isManufacturerExistingByIdAndName = await this.manufacturerService.IsManufacturerExistingByIdAndName(id, model.Name);

            if (isManufacturerExistingByIdAndName)
            {
                TempData.AddErrorMessage(string.Format(EntityExists, ManufacturerEntity));

                return(View(model));
            }

            await this.managerManufacturerService.EditAsync(id, model.Name, model.Address);

            TempData.AddSuccessMessage(string.Format(EntityModified, ManufacturerEntity));

            return(this.RedirectToManufacturersIndex(false));
        }
コード例 #4
0
        public async Task <IActionResult> Create(ManufacturerFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            bool isManufacturerExistingByName = await this.manufacturerService.IsManufacturerExistingByName(model.Name);

            if (isManufacturerExistingByName)
            {
                TempData.AddErrorMessage(string.Format(EntityExists, ManufacturerEntity));

                return(View(model));
            }

            await this.managerManufacturerService.CreateAsync(model.Name, model.Address);

            TempData.AddSuccessMessage(string.Format(EntityCreated, ManufacturerEntity));

            return(this.RedirectToManufacturersIndex(false));
        }