public IActionResult Edit(string id) { var existsBoulder = this.bouldersService .Exists(x => x.Id == id); if (!existsBoulder) { return(this.NotFound()); } var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; var valid = this.bouldersService .Exists(x => x.Id == id && x.AuthorId == userId); if (!valid) { return(this.Forbid()); } var boulder = new BoulderEditViewModel() { Id = id, BoulderInput = this.bouldersService .GetSingle <BoulderInputModel>(x => x.Id == id), }; this.SetEditListItems(boulder.BoulderInput); return(this.View(boulder)); }
public IActionResult Edit(string id) { var existsBoulder = this.bouldersService .Exists(x => x.Id == id); if (!existsBoulder) { return(this.NotFound()); } var boulder = new BoulderEditViewModel() { Id = id, BoulderInput = this.bouldersService .GetSingle <BoulderInputModel>(x => x.Id == id), }; this.SetSelectListItems(boulder.BoulderInput); return(this.View(boulder)); }
public async Task <IActionResult> Edit(string id, BoulderInputModel boulderInput) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; var valid = this.bouldersService .Exists(x => x.Id == id && x.AuthorId == userId); if (!valid) { return(this.Forbid()); } if (this.ModelState.ErrorCount == 1 && boulderInput.FormFile == null) { } else if (!this.ModelState.IsValid) { var boulder = new BoulderEditViewModel() { Id = id, BoulderInput = boulderInput, }; this.SetEditListItems(boulder.BoulderInput); return(this.View(boulder)); } var image = await this.cloudinaryService.SaveImageAsync(boulderInput.FormFile); await this.bouldersService.EditAsync(id, boulderInput, image); var boulderNameEncoded = HttpUtility.HtmlEncode(boulderInput.Name); this.TempData[GlobalConstants.MessageKey] = $"Successfully edited boulder <strong>{boulderNameEncoded}</strong>!"; return(this.RedirectToAction("Details", "Boulders", new { area = "Boulders", id })); }