Esempio n. 1
0
 public async Task <IActionResult> Edit(ManufacturerEditDto dto)
 {
     if (ModelState.IsValid)
     {
         memoryCache.Remove(GlobalConstants.CasheManufactorersInButtonName);
         if (await manufacturersService.NameTaken(dto.Name, dto.Id))
         {
             ModelState.AddModelError("Name", $"Name {dto.Name} is already used!");
             return(View(dto));
         }
         manufacturersService.EditManufacturer(dto);
         return(RedirectToAction(nameof(Manage)));
     }
     return(View(dto));
 }
        public void EditManufacturer(ManufacturerEditDto dto)
        {
            var manufacturer = manufacturerRepository.All().FirstOrDefault(x => x.Id == dto.Id);

            if (manufacturer is null)
            {
                return;
            }
            lock (ConcurencyMaster.LockManufacturersObj)
            {
                if (NameTaken(dto.Name, dto.Id).GetAwaiter().GetResult())
                {
                    return;
                }
                manufacturer.Name        = dto.Name;
                manufacturer.Email       = dto.Email;
                manufacturer.PhoneNumber = dto.PhoneNumber;
                manufacturer.WebAddress  = dto.WebAddress;
                manufacturerRepository.SaveChangesAsync().GetAwaiter().GetResult();
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id)
        {
            ManufacturerEditDto dto = await manufacturersService.GetManufacturerForEditingAsync(id);

            return(View(dto));
        }