Пример #1
0
        public async Task <IActionResult> Create(AddBikeMakerViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile, "Makers");
                }

                var bikeMakerEntity = _converterHelper.ToBikeMakerEntity(model, path);

                try
                {
                    _context.BikeMakers.Add(bikeMakerEntity);
                }
                catch (System.Exception err)
                {
                    ModelState.AddModelError(string.Empty, err.Message);
                    return(View(model));
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }