public async Task <bool> CreatePerformenceOrder(PerformenceOrderCreateInputModel inputModel) { var order = AutoMapper.Mapper.Map <Order>(inputModel); var user = this.userService.GetApplicationUserByName(inputModel.Username); var artist = await this.artistService.GetArtistIdByNameAsync(inputModel.ArtistNikname); var performence = this.performenceService.GetPerformenceByName(inputModel.PerformenceName); if (user == null || artist == null || performence == null) { throw new ArgumentNullException(GlobalConstants.OrderErr); } order.User = user; order.ArtistId = artist; order.PerformenceId = performence; order.Status = OrderStatus.Sent; await this.repositoryOrder.AddAsync(order); var result = await this.repositoryOrder.SaveChangesAsync(); return(result > 0); }
public IActionResult CreatePerformenceOrder([FromRoute] string id, string artistNikname) { string performenceTitle; try { performenceTitle = this.PerformenceService.GetPerformence(id).To <PerformneceProfileViewModel>().ToList().First().Title; var model = new PerformenceOrderCreateInputModel() { ArtistNikname = artistNikname, PerformenceName = performenceTitle }; return(this.View(model)); } catch (Exception) { return(this.View("Error", new ErrorViewModel() { RequestId = "This performence is not valid" })); } }
public async Task <IActionResult> CreatePerformenceOrder([FromRoute] string id, string artistNikname, PerformenceOrderCreateInputModel model) { model.ArtistNikname = artistNikname; model.Username = this.User.Identity.Name; model.PerformenceName = this.PerformenceService.GetPerformence(id).To <PerformneceProfileViewModel>().ToList().First().Title; if (this.ModelState.IsValid) { try { bool result = await this.OrderService.CreatePerformenceOrder(model); if (result) { return(this.Redirect(GlobalConstants.HomeUrl)); } } catch (ArgumentNullException a) { return(this.View("Error", new ErrorViewModel() { RequestId = a.Message })); } } var errors = this.ModelState.Values.SelectMany(v => v.Errors); foreach (var error in errors) { this.ModelState.AddModelError(string.Empty, error.ErrorMessage); } return(this.View()); }