private SoftwareDataset GetSoftwareInformation(SoftwareDatasetVM sd, int userID) { var sdToAdd = new SoftwareDataset() { UserID = userID, Title = sd.Title != null?sd.Title.Trim() : null, Authors = sd.Authors != null?sd.Authors.Trim() : null, CreationDate = DateTime.Now, Type = sd.Type, Link = sd.Link != null?sd.Link.Trim() : null, LinkText = sd.LinkText != null?sd.LinkText.Trim() : null, Description = sd.Description != null?sd.Description.Trim() : null }; var image = sd.Image; if (image != null && image.ContentLength > 0) { var fileName = Path.GetFileName(image.FileName); var guid = Guid.NewGuid().ToString(); var path = Path.Combine(Server.MapPath("~/images"), guid + '-' + fileName); image.SaveAs(path); var newImage = new BE.Image() { UserID = userID, Name = guid + "-" + fileName, FileSize = image.ContentLength, FilePath = path, CreationDate = System.DateTime.Now, ImageType = image.ContentType }; sdToAdd.Images.Add(newImage); } var upload = sd.Upload; if (upload != null && upload.ContentLength > 0) { var fileName = Path.GetFileName(upload.FileName); var guid = Guid.NewGuid().ToString(); var path = Path.Combine(Server.MapPath("~/uploads"), guid + "-" + fileName); upload.SaveAs(path); var newUpload = new BE.Upload() { FileName = guid + "-" + fileName, FileSize = upload.ContentLength, FilePath = path, CreationDate = System.DateTime.Now, FileType = upload.ContentType }; sdToAdd.Upload = newUpload; } return(sdToAdd); }
private Publication GetPublicationInformation(PublicationVM publication, string category, int userID) { var publicationToAdd = new Publication() { UserID = userID, Title = publication.Title != null?publication.Title.Trim() : null, Authors = publication.Authors != null?publication.Authors.Trim() : null, PublicationYear = Convert.ToInt32(publication.PublicationDate), CreationDate = DateTime.Now, Category = category != null?category.Trim() : null, Journal = publication.Journal != null?publication.Journal.Trim() : null, Conference = publication.Conference != null?publication.Conference.Trim() : null, Book = publication.Book != null?publication.Book.Trim() : null, Volume = publication.Volume != null?publication.Volume.Trim() : null, Institution = publication.Institution != null?publication.Institution.Trim() : null, PatentOffice = publication.PatentOffice != null?publication.PatentOffice.Trim() : null, PatentNumber = publication.PatentNumber != null?publication.PatentNumber.Trim() : null, ApplicationNumber = publication.ApplicationNumber != null?publication.ApplicationNumber.Trim() : null, Issue = publication.Issue != null?publication.Issue.Trim() : null, Pages = publication.Pages != null?publication.Pages.Trim() : null, Publisher = publication.Publisher != null?publication.Publisher.Trim() : null, KeyWords = publication.KeyWords != null?publication.KeyWords.Trim() : null, Abstract = publication.Abstract != null?publication.Abstract.Trim() : null, Source = publication.Source != null?publication.Source.Trim() : null, Link = publication.Link != null?publication.Link.Trim() : null, LinkText = publication.LinkText != null?publication.LinkText.Trim() : null }; var image = publication.Image; if (image != null && image.ContentLength > 0) { var fileName = Path.GetFileName(image.FileName); var guid = Guid.NewGuid().ToString(); var path = Path.Combine(Server.MapPath("~/images"), guid + '-' + fileName); image.SaveAs(path); var newImage = new BE.Image() { UserID = userID, Name = guid + "-" + fileName, FileSize = image.ContentLength, FilePath = path, CreationDate = System.DateTime.Now, ImageType = image.ContentType }; publicationToAdd.Images.Add(newImage); } var upload = publication.Upload; if (upload != null && upload.ContentLength > 0) { var fileName = Path.GetFileName(upload.FileName); var guid = Guid.NewGuid().ToString(); var path = Path.Combine(Server.MapPath("~/uploads"), guid + "-" + fileName); upload.SaveAs(path); var newUpload = new BE.Upload() { FileName = guid + "-" + fileName, FileSize = upload.ContentLength, FilePath = path, CreationDate = System.DateTime.Now, FileType = upload.ContentType }; publicationToAdd.Upload = newUpload; } return(publicationToAdd); }