コード例 #1
0
        public async Task <IActionResult> CreateSupplier(Supplier model)
        {
            if (ModelState.IsValid)
            {
                if (await _repository.SupplierWithTINExistsAsync(model))
                {
                    ModelState.AddModelError("SupplierExistsTIN", _stringLocalizer["A supplier with the same TIN exists"].ToString());
                }
                else
                {
                    model.LastModifiedByName = User.Identity.Name;
                    int result = await _repository.AddSupplierAsync(model);

                    if (result > 0)
                    {
                        TempData["SupplierMessage"] = _stringLocalizer["Supplier created successfully"].ToString();
                    }
                    else
                    {
                        TempData["SupplierMessage"] = _stringLocalizer["Failed to create"].ToString();
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewBag.Title = _stringLocalizer["Create Supplier"].ToString();
            return(View(model));
        }