public async Task <IActionResult> AddStep1(NewPublicationViewModel model, IFormFile File) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } model.NewPublication.Contributor = new Contributor(model.SelectedAuthorId); foreach (int id in model.SelectedAuthorIds) { model.NewPublication.Contributor.Contributors.Add(new Contributor_Author(id, AuthorRoleEnum.Secondary)); } model.NewPublication.Document = new Document(); model.NewPublication.Document.FileName = File.FileName; model.NewPublication.Document.DocType = (DocumentTypeEnum)model.PublicationType; using (var memoryStream = new MemoryStream()) { await File.CopyToAsync(memoryStream); model.NewPublication.Document.Content = memoryStream.ToArray(); } model.NewPublication.AddedBy = User.Identity.Name; int i = await _pubService.Add(model.NewPublication); return(RedirectToAction("Index")); }
public IActionResult NewSnapshot(NewPublicationViewModel viewModel) { var client = GetSnapshotClient(); var versionIds = new List <long>(); foreach (var resource in viewModel.ResourceTypes) { if (resource.ResourceList != null) { versionIds.AddRange(resource.ResourceList.Where(x => x.IsSelected).Select(x => x.ResourceVersionId).ToList()); } } var createSnapshotContract = new CreateSnapshotContract { BookTypes = viewModel.PublishBookTypes.Where(x => x.IsSelected).Select(x => x.BookType).ToList(), DefaultBookType = viewModel.DefaultBookType, ResourceVersionIds = versionIds, Comment = viewModel.Comment, ProjectId = viewModel.ProjectId }; client.CreateSnapshot(createSnapshotContract); return(RedirectToAction("Project", "Project", new { id = viewModel.ProjectId })); }
public async Task <IActionResult> AddStep1([FromQuery] PublicationTypeEnum pubType) { if (!ModelState.IsValid) { return(View(pubType)); } NewPublicationViewModel model = new NewPublicationViewModel(pubType); IEnumerable <Department> departments = await _departmentService.GetAll(); ViewData["DepartmentsList"] = new SelectList(departments, "Id", "DepartmentName"); IEnumerable <Author> authors = await _authService.GetAll(); IEnumerable <Publisher> publishers = await _publisherService.GetAll(); ViewData["AuthorsList"] = new SelectList(authors, "Id", "FName"); ViewData["PublishersList"] = new SelectList(publishers, "Id", "FullName"); model.NewPublication.Pagination = new Pagination(); model.NewPublication.Issue = new Issue(); model.NewPublication.PublicationResource = new PublicationResource(); switch (model.NewPublication.PublicationType) { case PublicationTypeEnum.Book: model.NewPublication.Book = new Book(); break; case PublicationTypeEnum.BookChapter: model.NewPublication.BookChapter = new BookChapter(); break; case PublicationTypeEnum.ConferencePaper: model.NewPublication.ConferencePaper = new ConferencePaper(); break; case PublicationTypeEnum.ConferenceProceeding: model.NewPublication.ConferenceProceeding = new ConferenceProceeding(); break; case PublicationTypeEnum.Journal: model.NewPublication.Journal = new Journal(); break; case PublicationTypeEnum.JournalArticle: model.NewPublication.JournalArticle = new JournalArticle(); break; case PublicationTypeEnum.Presentation: model.NewPublication.Presentation = new Presentation(); break; case PublicationTypeEnum.Dissertation: model.NewPublication.Dissertation = new Dissertation(); break; } return(View(model)); }
public async Task <IActionResult> Update([FromQuery] int pubId) { NewPublicationViewModel pub = new NewPublicationViewModel(); try { IEnumerable <Department> departments = await _departmentService.GetAll(); ViewData["DepartmentsList"] = new SelectList(departments, "Id", "DepartmentName"); IEnumerable <Author> authors = await _authService.GetAll(); IEnumerable <Publisher> publishers = await _publisherService.GetAll(); ViewData["AuthorsList"] = new SelectList(authors, "Id", "FName"); ViewData["PublishersList"] = new SelectList(publishers, "Id", "FullName"); pub.NewPublication = await _pubService.GetSingle(x => x.Id == pubId, x => x.Book, x => x.BookChapter, x => x.ConferencePaper, x => x.ConferenceProceeding, x => x.Contributor, x => x.Department, x => x.Dissertation, x => x.Document, x => x.Journal, x => x.Issue, x => x.JournalArticle, x => x.Pagination, x => x.PublicationResource, x => x.Publisher, x => x.Presentation, x => x.Contributor.Contributors); pub.SelectedAuthorId = pub.NewPublication.Contributor.GetPrimaryAuthId(); pub.SelectedAuthorIds = pub.NewPublication.Contributor.GetOtherAuthId(); } catch (Exception ex) { } return(View(pub)); }
public async Task <ActionResult> Add(NewPublicationViewModel model) { byte[] content = null; //array that will contain bytes of content if (model.ContentType == ContentType.Image) { //TODO: Bad code. Need holder for image types names if (Request.Files.Count > 0 && (Request.Files[0].ContentType == System.Net.Mime.MediaTypeNames.Image.Gif || Request.Files[0].ContentType == System.Net.Mime.MediaTypeNames.Image.Jpeg)) { content = FileUploader.UploadFile(Request.Files[0]); //Convert uploaded file to byte array } else //if file is empty or has unsupported type { ModelState.AddModelError("ImageFile", "For image post you must upload image file"); //Add validation error to model return(View(model)); } } else //if puplication has text content { content = Encoding.Default.GetBytes(model.Text); //convert text content to byte array } var publication = new CreatePublicationData() //create new publication object that contains main data to add to source { Author = User.Identity.Name, Content = content, ContentType = model.ContentType, Title = model.Title }; var result = await ContentService.CreatePublication(publication); //trying to add publication data to source if (result.Succedeed) //if data was successfully added { return(RedirectToRoute(new { controller = "Home", action = "Hot" })); } ModelState.AddModelError("", "Cant`create publication: " + result.Message); //add validation error to model return(View()); }