Example #1
0
        public async Task <IActionResult> EditSupplier(SupplierEditViewModel model)
        {
            int result = 0;

            if (ModelState.IsValid)
            {
                model.Supplier.LastModifiedByName = User.Identity.Name;
                result = await _repository.UpdateSupplierAsync(model.Supplier);

                if (result < 1)
                {
                    TempData["SupplierMessage"] = _stringLocalizer["Nothing changed"].ToString();
                    return(RedirectToAction(nameof(Index)));
                }
                TempData["SupplierMessage"] = _stringLocalizer["Supplier modified successfully"].ToString();
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                model.Supplier.Contacts = (await _repository.GetSupplierByIdAsync(model.Supplier.Id)).Contacts;
                ViewBag.Title           = _stringLocalizer["Edit Supplier"].ToString();
                return(View(model));
            }
        }