public ActionResult Edit(int id) { PublishingDTO publishing = publishingService.GetPublishing(id); if (publishing == null) { return(null); } PublishingEditViewModel editViewModel = new PublishingEditViewModel { Publishing = mapper.Map <PublishingViewModel>(publishing), AvailableTopics = mapper .Map <IEnumerable <TopicViewModel> >(publishingService.GetTopicsNotInPublishing(id)), TopicsAtPublishing = mapper .Map <IEnumerable <TopicViewModel> >(publishing.Topics), EditorsAtPublishing = mapper .Map <IEnumerable <PublishingEmployeeViewModel> >(publishing.Editors), JournalistsAtPublishing = mapper .Map <IEnumerable <PublishingEmployeeViewModel> >(publishing.Journalists), AvailableEditors = mapper .Map <IEnumerable <PublishingEmployeeViewModel> >(publishingService.GetEditorsNotInPublishing(id)), AvailableJournalists = mapper .Map <IEnumerable <PublishingEmployeeViewModel> >(publishingService.GetJournalistsNotInPublishing(id)), }; return(View(editViewModel)); }
public ActionResult Edit(PublishingViewModel publishing) { // TODO: Валидация редактированного журнала PublishingDTO publishingDTO = mapper.Map <PublishingDTO>(publishing); publishingService.UpdatePublishing(publishingDTO); return(RedirectToAction("List")); }
public void UpdatePublishing(PublishingDTO publishing) { Publishing publishingEntity = mapper.Map <Publishing>(publishing); var employees = publishing.Journalists.Concat(publishing.Editors); publishingEntity.PublishingEmployees = employees .Select(e => new PublishingEmployee { EmployeeId = e.Id, PublishingId = publishing.Id }).ToList(); unitOfWork.Publishings.Update(publishingEntity); unitOfWork.Save(); }