Exemple #1
0
        public async Task <IActionResult> Create(CarModelAdminBindingModel model, string manufacturerId)
        {
            if (!this.ModelState.IsValid)
            {
                this.Error(NotificationMessages.ModelInvalidName);
                return(this.RedirectToAction("Manufacturer", new { id = manufacturerId }));
            }

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

            serviceModel.ManufacturerId = manufacturerId;

            if (await this.modelsService.ExistsAsync(serviceModel))
            {
                this.Error(NotificationMessages.ModelExists);
                return(this.RedirectToAction("Manufacturer", new { id = manufacturerId }));
            }

            var result = await this.modelsService.CreateAsync(serviceModel);

            if (result)
            {
                this.Success(NotificationMessages.ModelCreated);
            }
            else
            {
                this.Error(NotificationMessages.ModelCreateError);
            }

            return(this.RedirectToAction("Manufacturer", new { id = manufacturerId }));
        }
Exemple #2
0
        public async Task <IActionResult> Edit(CarModelAdminBindingModel model, string id, string manufacturerId)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

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

            serviceModel.Id             = id;
            serviceModel.ManufacturerId = manufacturerId;

            if (await this.modelsService.ExistsAsync(serviceModel))
            {
                this.Error(NotificationMessages.ModelExists);
                return(this.RedirectToAction("Manufacturer", new { id = manufacturerId }));
            }

            var result = await this.modelsService.UpdateAsync(serviceModel);

            if (result)
            {
                this.Success(NotificationMessages.ModelEdited);
            }
            else
            {
                this.Error(NotificationMessages.ModelEditError);
            }

            return(this.RedirectToAction("Manufacturer", new { id = manufacturerId }));
        }