public async Task <IActionResult> Edit(SlopeFormServiceModel model, int id) { if (!ModelState.IsValid) { return(View(model)); } if (!await this.slopeService.SlopeExistsAsync(id)) { TempData.AddErrorMessage($"Slope does not exist"); return(RedirectToHome()); } if (!User.IsInRole(WebConstants.AdministratorRole)) { if (!await this.slopeService.IsSlopeOfUserAsync(id, User.Identity.Name)) { TempData.AddErrorMessage("You are not the owner of the slope"); return(RedirectToHome()); } } var result = await this.slopeService.EditAsync(model.Name, model.Length, model.Difficulty, model.Status, id); if (!result) { TempData.AddErrorMessage($"Slope {model.Name} was not edited"); return(RedirectToHome()); } TempData.AddSuccessMessage($"Slope was edited"); return(RedirectToHome()); }
public async Task <IActionResult> Create(SlopeFormServiceModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await userManager.FindByNameAsync(this.User.Identity.Name); var userId = user.Id; await this.slopeService.CreateAsync(model.Name, model.Length, model.Difficulty, model.Status, userId); TempData.AddSuccessMessage($"Slope {model.Name} was sucessfully created"); return(RedirectToHome()); }