コード例 #1
0
        public async Task <IActionResult> CreateMeasurmentUnit(MeasurmentUnit model)
        {
            if (ModelState.IsValid)
            {
                if (await _repository.MeasurmentUnitExistsAsync(model.Name))
                {
                    ModelState.AddModelError("UnitExists", _stringLocalizer["A measuring unit with that name exists"].ToString());
                }
                else
                {
                    model.LastModifiedByName = User.Identity.Name;
                    int result = await _repository.AddMeasurmentUnitAsync(model);

                    if (result < 1)
                    {
                        TempData["MeasurmentUnitMessage"] = _stringLocalizer["Nothing added"].ToString();
                    }
                    else
                    {
                        TempData["MeasurmentUnitMessage"] = _stringLocalizer["Measuring unit added successfully"].ToString();
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewBag.Title = _stringLocalizer["Create Measurment Unit"].ToString();
            return(View(model));
        }