public async Task <IActionResult> Create(IconViewModel model) { if (ModelState.IsValid) { try { if (model.Icons == null) { model.Icons = new List <Icon>(); } if (_iconService.Get(x => x.GameId == model.GameId && x.Value == model.Value) != null) { ModelState.AddModelError("Value", "Value must be unique"); model.Icons.AddRange(_iconService.List(x => x.GameId == model.GameId)); return(View(model)); } _iconService.BeginTransaction(); var icon = helper.GetIcon(model); icon.Id = _iconService.Add(icon); if (icon.Id < 0) { throw new Exception("database error"); } await helper.FileUploadAsync(model.IconFile, icon.IconName, "Icon"); model.Icons.AddRange(_iconService.List(x => x.GameId == model.GameId)); _iconService.CommitTransaction(); return(View(nameof(Create), model)); } catch (Exception ex) { _iconService.RollbackTransaction(); } } return(View(model)); }