public async Task <IActionResult> Update(MovieViewModel model) { if (!this.ModelState.IsValid) { return(View(model)); } try { var movie = await this.movieService.GetMovieByIdAsync(model.Id); if (movie == null) { return(NotFound()); } string posterName = null; string sliderName = null; if (model.PosterImage != null) { posterName = optimizer.OptimizeImage(model.PosterImage, 268, 182); } if (model.SliderPoster != null) { sliderName = optimizer.OptimizeImage(model.SliderPoster, 500, 1300); } if (model.Poster != null) { optimizer.DeleteOldImage(model.Poster); } if (model.SliderImage != null) { optimizer.DeleteOldImage(model.SliderImage); } movie = await this.movieService .UpdateMovieAsync(movie, model.Trailer, model.Description, posterName, sliderName); if (movie.Trailer == model.Trailer && movie.Description == model.Description && movie.Poster == posterName && movie.SliderImage == sliderName) { StatusMessage = string.Format(WebConstants.MovieSuccessfullyUpdated, model.Title); } return(RedirectToAction("Details", "Movies", new { id = movie.Id })); } catch (ArgumentException ex) { StatusMessage = ex.Message; return(RedirectToAction("Update", "Movies", new { id = model.Id })); } }
public async Task <IActionResult> Update(LogbookViewModel model) { if (!this.ModelState.IsValid) { return(BadRequest(string.Format(WebConstants.UnableToUpdateLogbook, model.Name))); } try { var logbookDTO = await this.logbookService.GetLogbookById(model.Id); string imageName = null; if (model.LogbookPicture != null) { imageName = optimizer.OptimizeImage(model.LogbookPicture, 400, 800); } if (model.Picture != null) { optimizer.DeleteOldImage(model.Picture); } logbookDTO = await this.logbookService.UpdateLogbookAsync(model.Id, model.Name, model.BusinessUnitId, imageName); if (logbookDTO.Name != model.Name) { return(BadRequest(string.Format(WebConstants.UnableToUpdateLogbook, model.Name))); } return(Ok(string.Format(WebConstants.LogbookUpdated, model.Name))); } catch (NotFoundException ex) { return(BadRequest(ex.Message)); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } catch (AlreadyExistsException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { log.Error("Unexpected exception occured:", ex); return(RedirectToAction("Error", "Home")); } }
public async Task <IActionResult> Update(BusinessUnitViewModel model) { if (!this.ModelState.IsValid) { return(BadRequest(string.Format(WebConstants.UnableToUpdateBusinessUnit, model.Name))); } try { var businessUnitDTO = await this.businessUnitService.GetBusinessUnitById(model.Id); string imageName = null; if (model.BusinessUnitPicture != null) { imageName = optimizer.OptimizeImage(model.BusinessUnitPicture, 400, 800); } if (model.Picture != null) { optimizer.DeleteOldImage(model.Picture); } businessUnitDTO = await this.businessUnitService.UpdateBusinessUnitAsync(model.Id, model.Name, model.Address, model.PhoneNumber, model.Information, model.Email, model.CategoryId, model.TownId, imageName); if (businessUnitDTO.Name != model.Name) { return(BadRequest(string.Format(WebConstants.UnableToUpdateBusinessUnit, model.Name))); } return(Ok(string.Format(WebConstants.BusinessUnitUpdated, model.Name))); } catch (NotFoundException ex) { return(BadRequest(ex.Message)); } catch (AlreadyExistsException ex) { return(BadRequest(ex.Message)); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { log.Error("Unexpected exception occured:", ex); return(RedirectToAction("Error", "Home")); } }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { string imageName = null; if (model.UserImage != null) { imageName = optimizer.OptimizeImage(model.UserImage, 400, 800); } if (model.Image != null) { optimizer.DeleteOldImage(model.Image); } var user = new User { Email = model.Email, UserName = model.UserName, Picture = imageName }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); if (model.UserRole == "Manager") { await _userManager.AddToRoleAsync(user, "Manager"); } else if (model.UserRole == "Moderator") { await _userManager.AddToRoleAsync(user, "Moderator"); } else if (model.UserRole == "Admin") { await _userManager.AddToRoleAsync(user, "Admin"); } var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); _logger.LogInformation("User created a new account with password."); return(Ok(string.Format(WebConstants.UserCreated, model.UserName))); } return(BadRequest("Invalid attempt.")); } return(BadRequest(WebConstants.EnterValidData)); }
public async Task <IActionResult> Edit(NoteViewModel model) { try { string imageName = null; if (model.NoteImage != null) { imageName = optimizer.OptimizeImage(model.NoteImage, 600, 800); } if (model.Image != null) { optimizer.DeleteOldImage(model.Image); } var userId = this.wrapper.GetLoggedUserId(User); var noteDTO = await this.noteService .EditNoteAsync(model.Id, userId, model.Description, imageName, model.CategoryId); if (noteDTO.Description != model.Description) { return(BadRequest(string.Format(WebConstants.UnableToEditNote))); } return(Ok(string.Format(WebConstants.NoteEdited))); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } catch (NotFoundException ex) { return(BadRequest(ex.Message)); } catch (NotAuthorizedException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { log.Error("Unexpected exception occured:", ex); return(RedirectToAction("Error", "Home")); } }
public async Task <IActionResult> Update(ActorViewModel model) { if (!this.ModelState.IsValid) { return(View(model)); } try { var actor = await this.actorService.GetActorByIdAsync(model.Id); if (actor == null) { return(NotFound()); } string imageName = null; if (model.ActorPicture != null) { imageName = optimizer.OptimizeImage(model.ActorPicture, 268, 182); } if (model.Picture != null) { optimizer.DeleteOldImage(model.Picture); } actor = await this.actorService .UpdateActorAsync(actor, imageName, model.Biography); if (actor.FirstName == model.FirstName && actor.LastName == model.LastName && actor.Picture == model.Picture && actor.Biography == model.Biography) { StatusMessage = string.Format(WebConstants.ActorDetailsUpdated, model.FirstName, model.LastName); } return(RedirectToAction("Details", "Actors", new { id = actor.Id })); } catch (ArgumentException ex) { StatusMessage = ex.Message; return(RedirectToAction("Update", "Actors", new { id = model.Id })); } }