public static void ManufacturerMap(this Manufacturer destination, ManufacturerView source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (destination == null) { throw new ArgumentNullException(nameof(destination)); } var now = DateTime.UtcNow; if (destination.CreatedAt == null) { destination.CreatedAt = now; } destination.Name = source.Name; destination.Info = source.Info; destination.Logo = source.Logo; destination.ModifiedAt = now; destination.Active = source.Active; }
public IActionResult UpdateManufacturer(ManufacturerView manufacturerView) { var manufacturer = _service.ConvertViewModelToData(manufacturerView); _manufacturer.Update(manufacturer); return(RedirectToAction("Index", "Manufacturer")); }
public async Task <string> Manufacturer() { var manufactBLLList = await _serv.GetAllAsync(); var manufactViewList = ManufacturerView.MapToView(manufactBLLList, _mapper); return(JsonConvert.SerializeObject(manufactViewList, Formatting.Indented)); }
public ManufacturerView ConvertDataModelToView(Manufacturer manufacturer) { var newManufacturer = new ManufacturerView(); newManufacturer.Id = manufacturer.Id; newManufacturer.name = manufacturer.Name; return(newManufacturer); }
public ActionResult Edit(ManufacturerView manufacturerView) { if (!ModelState.IsValid) { return(View(manufacturerView)); } manufacturerHelper.Save(manufacturerView); return(RedirectToAction("Index")); }
public async Task <ActionResult <Manufacturer> > PostManufacturer(ManufacturerView manufacturerView) { var manufacturer = new Manufacturer(); manufacturer.ManufacturerMap(manufacturerView); _context.Manufacturers.Add(manufacturer); await _context.SaveChangesAsync(); return(CreatedAtAction("GetManufacturer", new { id = manufacturer.Id }, manufacturer)); }
public async Task <string> GetById(int id) { var manufacturerBLLById = await _serv.GetByIdAsync(id); if (manufacturerBLLById == null) { return(NotFound().ToString()); } var manufacturerViewById = ManufacturerView.MapToView(manufacturerBLLById, _mapper); return(JsonConvert.SerializeObject(manufacturerViewById, Formatting.Indented));; }
public IActionResult Create(ManufacturerView manufacturer) { var newManufacturer = _service.ConvertViewModelToData(manufacturer); try { _manufacturer.AddManufacturer(newManufacturer); } catch (Exception e) { throw e; } return(RedirectToAction("Index", "Manufacturer")); }
public async Task <bool> Post(ManufacturerView manufacturer) { if (manufacturer == null) { return(false); } if (ModelState.IsValid) { var manufacturereBLL = ManufacturerView.MapToBLL(manufacturer, _mapper); var postResult = await _serv.AddAsync(manufacturereBLL); return(postResult); } return(false); }
public Manufacturer ConvertViewModelToData(ManufacturerView manufacturer) { var newManufacturer = new Manufacturer(); if (manufacturer.Id == null) { newManufacturer.Id = Guid.NewGuid(); } else { newManufacturer.Id = manufacturer.Id; } newManufacturer.Name = manufacturer.name; return(newManufacturer); }
public ActionResult CreateManufacturer(ManufacturerView _ManufacturerView) { var anyManufacturer = Repository.Manufacturers.Any(p => string.Compare(p.Name, _ManufacturerView.Name) == 0); if (anyManufacturer) { ModelState.AddModelError("Name", "Производитель с таким наименованием уже существует"); } if (ModelState.IsValid) { var _Manufacturer = (Manufacturer) ModelMapper.Map(_ManufacturerView, typeof (ManufacturerView), typeof (Manufacturer)); Repository.CreateManufacturer(_Manufacturer); return RedirectToAction("Index"); } return View(_ManufacturerView); }
public ActionResult EditManufacturer(ManufacturerView _ManufacturerView) { var anyManufacturer = Repository.Manufacturers.Where(p=>p.ID!=_ManufacturerView.ID).Any(p => string.Compare(p.Name, _ManufacturerView.Name) == 0); if (anyManufacturer) { ModelState.AddModelError("Name", "Производитель с таким наименованием уже существует"); } if (ModelState.IsValid) { var _Manufacturer = Repository.Manufacturers.FirstOrDefault(p => p.ID == _ManufacturerView.ID); ModelMapper.Map(_ManufacturerView, _Manufacturer, typeof (ManufacturerView), typeof (Manufacturer)); Repository.UpdateManufacturer(_Manufacturer); return RedirectToAction("Index"); } return View(_ManufacturerView); }
public ActionResult CreateManufacturer() { var newManufacturerView = new ManufacturerView(); return View(newManufacturerView); }