Beispiel #1
0
        public IActionResult Update(int id, EditManufacturerViewModel model)
        {
            if (id != 0)
            {
                model.ManufacturerId = id;
            }

            if (ModelState.IsValid)
            {
                var man = _databaseContext.Manufacturer.FirstOrDefault(m => m.ManufacturerId == id);

                man.ManufacturerName = model.ManufacturerName;
                man.About            = model.About;
                man.ImagePath        = model.ImagePath;

                var x = _databaseContext.Manufacturer.Where(g => (g.ManufacturerName == man.ManufacturerName && g.ManufacturerId != id)).ToList();
                if (x.Count > 0)
                {
                    TempData[Constants.Message]       = $"Proizvođač tog imena već postoji.\n";
                    TempData[Constants.ErrorOccurred] = true;
                    return(View("Edit", model));
                }

                TempData["Success"] = true;
                _databaseContext.SaveChanges();
                TempData[Constants.Message]       = $"Proizvođač je promijenjen";
                TempData[Constants.ErrorOccurred] = false;
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View("Edit", model));
            }
        }
Beispiel #2
0
        public IActionResult UpdateManufacturer(EditManufacturerViewModel viewModel)
        {
            var manufacturer = mapper.Map <Manufacturer>(viewModel.ManufacturerDto);

            manufacturer.Id = viewModel.ManufacturerId;

            manufacturerRepo.Update(manufacturer);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Detail(string id)
        {
            var manufacturer = await this.manufacturerService.GetCurrentManufacturer(id);

            var viewModel = new EditManufacturerViewModel
            {
                ManufacturerDetail = manufacturer,
            };

            return(this.View(viewModel));
        }
Beispiel #4
0
        public IActionResult EditManufacturer(long id)
        {
            var manufacturer    = manufacturerRepo.Get(id);
            var manufacturerDto = mapper.Map <ManufacturerForUpdateDto>(manufacturer);

            var viewModel = new EditManufacturerViewModel
            {
                ManufacturerDto = manufacturerDto,
                ManufacturerId  = id
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> EditManufacturer(EditManufacturerViewModel editManufacturerViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(editManufacturerViewModel));
            }

            var manufacturerDto = _mapper.Map <ManufacturerDTO>(editManufacturerViewModel);

            _manufacturerService.Update(manufacturerDto);
            await _manufacturerService.SaveChangesAsync();

            return(RedirectToAction(nameof(GetManufacturerList), CURRENT_CONTROLLER_NAME));
        }
        public async Task <IActionResult> Edit([FromForm] EditManufacturerViewModel model)
        {
            var isCreate = false;

            if (GlobalConstants.Editors.Contains(this.User.Identity.Name))
            {
                isCreate = await this.manufacturerService.EditManufacturer(model.Id, model.Name);
            }

            if (isCreate)
            {
                this.TempData["EditManufacturer"] = $"Произовдител {model.Name} е редактиран!";
            }

            return(this.RedirectToAction("All"));
        }
Beispiel #7
0
        public async Task <IActionResult> ModifyManufacturer([FromBody] EditManufacturerViewModel model)
        {
            if (model == null)
            {
                return(Json(new Result(ApplicationResources.UserInterface.Common.ModifyManufacturerError)));
            }

            var result = await _cubeSrvice.UpdateManufacturerAsync(Convert.ToInt32(model.Identity),
                                                                   model.Name, model.Country, Convert.ToUInt16(model.Year));

            if (!result.IsFaulted)
            {
                result.JsonData = await _cubeSrvice.GetAllManufacturersAsync();
            }

            return(Json(result));
        }
Beispiel #8
0
        public ViewResult Edit(int id)
        {
            var man = _databaseContext.Manufacturer
                      .FirstOrDefault(p => p.ManufacturerId == id);

            ViewData["Success"] = TempData["Success"];

            var model = new EditManufacturerViewModel
            {
                About            = man.About,
                ImagePath        = man.ImagePath,
                ManufacturerId   = man.ManufacturerId,
                ManufacturerName = man.ManufacturerName
            };

            return(View(model));
        }