Exemple #1
0
        public async Task <IActionResult> AddModel(ModelBrandViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    await _brandRepository.AddModelAsync(model);

                    var brandId = model.BrandId;

                    return(RedirectToAction($"Details/{brandId}"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        if (ModelState.IsValid)
                        {
                            ModelState.AddModelError(string.Empty, $"There is allready a Model registered with the name {model.Name} please insert another");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }
                }
            }

            ViewBag.Id = model.BrandId;
            return(this.View(model));
        }