public async Task <IActionResult> Edit(LiftCardFormServiceModel model, int id) { if (!ModelState.IsValid) { return(View(model)); } if (!await this.liftCardService.LiftCardExistsAsync(id)) { TempData.AddErrorMessage("Lift card does not exist"); return(RedirectToHome()); } if (!User.IsInRole(WebConstants.AdministratorRole)) { if (!await this.liftCardService.IsLiftCardOfUser(id, User.Identity.Name)) { TempData.AddErrorMessage("You do not own this lift card"); return(RedirectToHome()); } } await this.liftCardService.EditAsync(model, id); TempData.AddSuccessMessage("Lift card was edited"); return(RedirectToHome()); }
public async Task EditAsync(LiftCardFormServiceModel model, int id) { var liftCard = await this.GetLiftCardEntityAsync(id); liftCard.Name = model.Name; liftCard.NumberOfPeople = model.NumberOfPeople; liftCard.Price = model.Price; liftCard.MaxDaysToUse = model.MaxDaysToUse; await this.db.SaveChangesAsync(); }
public async Task <IActionResult> Create(LiftCardFormServiceModel model) { if (!ModelState.IsValid) { return(View(model)); } await this.liftCardService.CreateAsync(model); TempData.AddSuccessMessage("Lift card created"); return(RedirectToHome()); }
public async Task CreateAsync(LiftCardFormServiceModel model) { var liftCard = new LiftCard { Name = model.Name, Price = model.Price, MaxDaysToUse = model.MaxDaysToUse, NumberOfPeople = model.NumberOfPeople, ResortId = model.ResortId }; await db.LiftCards.AddAsync(liftCard); await db.SaveChangesAsync(); }