public async Task <IActionResult> Edit(EditClubInputModel model, string id) { bool isFileValid = true; if (model.ImageFile != null) { isFileValid = this.clubService.IsFileValid(model.ImageFile); } if (ModelState.IsValid && isFileValid && model.Interests.Any() == true) { string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.clubService.EditClub(model, id); return(this.Redirect("/Club/Details/" + id)); } var interests = this.clubService.GetInterests(); model.InterestsToList = interests; if (model.Interests.Any() == false) { ModelState.AddModelError(ClubFields.Interests, ErrorMessages.ClubInterestsRequired); } var bindingModel = new EditClubBindingModel() { Id = id, Name = model.Name, Fee = model.Fee, IsPublic = model.IsPublic, PriceType = model.PriceType, Description = model.Description, Town = model.Town, PictureUrl = model.PictureUrl, ImageFile = model.ImageFile, InterestsToList = interests }; return(this.View(bindingModel)); }
public async Task <Club> EditClub(EditClubInputModel model, string id) { string currentUrl = await this.cloudinaryService.UploadImage(model.ImageFile); Club club = await this.dbContext .Clubs .FirstOrDefaultAsync(x => x.Id == id); club.Name = model.Name; club.Fee = (decimal)model.Fee; club.PriceType = (PriceType)Enum.Parse(typeof(PriceType), model.PriceType, true); club.IsPublic = (bool)model.IsPublic; club.Description = model.Description; club.Town = model.Town; club.PictureUrl = currentUrl != "" ? currentUrl : model.PictureUrl; club.Interests = this.userService.InterestsToString(model.Interests); await this.dbContext.SaveChangesAsync(); return(club); }