public async Task <IActionResult> Add(CinemaInputModel input) { if (cinemaBusiness.IsAlreadyAdded(input.Name)) { ModelState.AddModelError("Added", "Cinema already added!"); } var user = await userManager.GetUserAsync(User); if (user?.Cinema != null) { ModelState.AddModelError("Added", "You already manage your cinema."); } if (!ModelState.IsValid) { return(this.View()); } var cinema = new Cinema { Name = input.Name, Country = input.Country, City = input.City, ManagerId = userManager.GetUserId(User) }; await cinemaBusiness.AddAsync(cinema); return(this.RedirectToAction("Manage", "Cinemas", new { cinema.Id })); }
public async Task <IActionResult> Update(CinemaInputModel input, string id) { var user = await userManager.GetUserAsync(User); var cinema = await cinemaBusiness.GetAsync(id); if (user?.Id == cinema?.ManagerId) { if (!ModelState.IsValid) { return(this.View(input)); } var data = mapper.MapToCinemaData(input); data.Id = cinema.Id; data.ManagerId = cinema.ManagerId; var ticketUrlPattern = Url.ActionLink("Index", "Tickets"); await cinemaBusiness.UpdateAsync(data, ticketUrlPattern); return(RedirectToAction("Manage", "Cinemas", new { Id = id })); } return(RedirectToAction("Index", "Cinemas")); }
///<summary> /// Converts CinemaInputModel object to Cinema ///</summary> ///<param name="input"> CinemaInputModel object to map from</param> ///<returns>Mapped instance of type <see cref="Cinema"/></returns> public Cinema MapToCinemaData(CinemaInputModel input) { var model = MapSimilarProperties <CinemaInputModel, Cinema>(input); return(model); }