public ActionResult New(PublisherWebModel publisher) { if (!ModelState.IsValid) { return(View(publisher)); } _publisherService.AddNewPublisher(Mapper.Map <PublisherWebModel, PublisherBLModel>(publisher)); return(RedirectToAction("Publisher", new { companyName = publisher.CompanyName })); }
public ActionResult New(PublisherCreateViewModel model) { _logger.Information("Action: New; Controller: Publisher; Call method: POST;"); try { if (!ModelState.IsValid) { model.ExistingAuthors = ConvertToSelectListAuthors(_publisherService.GetExistingAuthors()); model.ExistingTopics = ConvertToSelectListTopics(_publisherService.GetExistingTopics()); return(View(model)); } if (model.Image == null || model.Image.ContentLength == 0) { model.ExistingAuthors = ConvertToSelectListAuthors(_publisherService.GetExistingAuthors()); model.ExistingTopics = ConvertToSelectListTopics(_publisherService.GetExistingTopics()); ModelState.AddModelError("", "This field is required"); return(View(model)); } if (!validImageTypes.Any(model.Image.ContentType.Contains)) { model.ExistingAuthors = ConvertToSelectListAuthors(_publisherService.GetExistingAuthors()); model.ExistingTopics = ConvertToSelectListTopics(_publisherService.GetExistingTopics()); ModelState.AddModelError("", "Please choose either jpg, jpeg or png format file"); return(View(model)); } Publisher publisherToAdd = new Publisher(); publisherToAdd.Title = model.Title; publisherToAdd.Description = model.Description; publisherToAdd.MonthlySubscriptionPrice = model.MonthlySubscriptionPrice; publisherToAdd.ImagePath = GenerateImageSavePath(model.Image); publisherToAdd.Authors = ConvertToListAuthors(model.Authors); publisherToAdd.Topics = ConvertToListTopics(model.Topics); var newPublisherId = _publisherService.AddNewPublisher(publisherToAdd); return(RedirectToAction("Details", "Publisher", new { id = newPublisherId })); } catch (Exception e) { LogException(e); return(RedirectToAction("Index", "Error", new { exceptionType = e.GetType().Name })); } }