public void Add(SaveBrandDto saveBrandDto) { var brand = _mapper.Map <SaveBrandDto, Brand>(saveBrandDto); _unitOfWork.Brands.Add(brand); _unitOfWork.Complete(); }
public void Update(SaveBrandDto saveBrandDto) { var brand = _unitOfWork.Brands.GetBy(saveBrandDto.ID); if (brand == null) { return; } _mapper.Map <SaveBrandDto, Brand>(saveBrandDto, brand); _unitOfWork.Complete(); }
public IActionResult Edit(BrandEditVm model) { if (HttpContext.Session.GetInt32("LoginLevel") != 2) { ViewBag.checkLogin = 0; return(View("../Home/AddCart")); } if (ModelState.IsValid) { var brands = _service.GetAll(); foreach (BrandDto item in brands) { if (item.Name.ToLower().Equals(model.Name.ToLower()) && item.ID != model.Id) { var x = _brandService.GetList(); ViewBag.StatusList = x.StatusList; ViewBag.BrandEditErrorMessage = "Error!"; return(View(model)); } } BrandDto brandDto = _service.GetBrand(model.Id); SaveBrandDto saveBrandDto = _mapper.Map <BrandDto, SaveBrandDto>(brandDto); saveBrandDto.Name = model.Name; saveBrandDto.Status = model.Status; //saveBrandDto.PhotoPath = model.ExistPhotoPath; if (model.Photo != null) { if (model.ExistPhotoPath != null) { string filePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", model.ExistPhotoPath); System.IO.File.Delete(filePath); } saveBrandDto.PhotoPath = ProcessUploadedFile(model); } _service.Update(saveBrandDto); return(View("Detail", _service.GetBrand(saveBrandDto.ID))); } return(View()); }
public IActionResult Create(BrandCreateVm model) { if (HttpContext.Session.GetInt32("LoginLevel") != 2) { ViewBag.checkLogin = 0; return(View("../Home/AddCart")); } if (!ModelState.IsValid) { var x = _brandService.GetList(); ViewBag.StatusList = x.StatusList; return(View()); } string uniqueFileName = ProcessUploadedFile(model); SaveBrandDto saveBrandDto = new SaveBrandDto() { Name = model.Name, Status = model.Status, PhotoPath = uniqueFileName }; var brands = _service.GetAll(); foreach (BrandDto item in brands) { if (saveBrandDto.Name.ToLower() == item.Name.ToLower()) { var x = _brandService.GetList(); ViewBag.StatusList = x.StatusList; ViewBag.BrandDuplicateErrorMessage = "Error! This Brand already exists"; return(View()); } } _service.Add(saveBrandDto); return(RedirectToAction("Index")); }