Beispiel #1
0
        public ActionResult Index()
        {
            ResearchBlogViewModel model = new ResearchBlogViewModel();

            rr.ClearUnreadPosts(User.Identity.GetUserId());
            model.Posts = rr.GetAll().ToList();


            foreach (var post in model.Posts)
            {
                ResearchPostFileCombo rpfc = new ResearchPostFileCombo()
                {
                    AttatchedPost = post
                };
                using (DataContext context = new DataContext())
                {
                    ResearchPost rp               = new ResearchPost();
                    var          ResearchPostId   = context.ResearchPosts.Select(r => r.Id);
                    var          categoryFiles    = context.UserFiles.Where(x => ResearchPostId.Contains(x.BlogPostId)).ToList();
                    var          picExtensionList = new List <string>()
                    {
                        ".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG"
                    };
                    var picList = categoryFiles.Where(x => picExtensionList.Contains(x.FileExtension)).Where(x => x.BlogPostId == post.Id);
                    rpfc.AttatchedPics = picList.ToList();
                    rpfc.AttatchedDocs = categoryFiles.Where(x => x.BlogPostId == post.Id).Where(x => !picExtensionList.Contains(x.FileExtension)).ToList();
                }
                model.PostFileCombinations.Add(rpfc);
            }

            return(View(model));
        }
 public void DeletePost(Guid id)
 {
     using (DataContext context = new DataContext())
     {
         ResearchPost postToDelete = context.ResearchPosts.Find(id);
         context.ResearchPosts.Remove(postToDelete);
         context.SaveChanges();
     }
 }
 public ResearchPost GetPost(Guid id)
 {
     using (DataContext db = new DataContext())
     {
         ResearchPost post = db.ResearchPosts.SingleOrDefault(p => p.Id.Equals(id));
         var          user = db.Users.SingleOrDefault(x => x.Id.Equals(post.UserId));
         post.ApplicationUser = user;
         return(post);
     }
 }
 public void AddPost(ResearchPost post)
 {
     using (DataContext db = new DataContext())
     {
         var users = db.Users.ToList();
         users.ForEach(u => u.UnreadResearchPosts.Add(post));
         db.ResearchPosts.Add(post);
         db.SaveChanges();
     }
 }
 public void EditPost(ResearchPost post)
 {
     using (DataContext db = new DataContext())
     {
         ResearchPost postToEdit = GetPost(post.Id);
         postToEdit.Title           = post.Title;
         postToEdit.Content         = post.Content;
         db.Entry(postToEdit).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Beispiel #6
0
 public ActionResult UploadFile(HttpPostedFileBase[] filesToUpload, ResearchPost ownerPost)
 {
     using (DataContext context = new DataContext())
     {
         foreach (var fileToUpload in filesToUpload)
         {
             var newFile = new UserFile();
             newFile.BlogPostId    = ownerPost.Id;
             newFile.FileID        = Guid.NewGuid();
             newFile.FileName      = fileToUpload.FileName;
             newFile.FileExtension = System.IO.Path.GetExtension(fileToUpload.FileName).ToString();
             using (var reader = new System.IO.BinaryReader(fileToUpload.InputStream))
             {
                 newFile.FileBytes = reader.ReadBytes(fileToUpload.ContentLength);
             }
             context.UserFiles.Add(newFile);
         }
         context.SaveChanges();
     }
     return(RedirectToAction("Index", "Home"));
 }
Beispiel #7
0
 public ActionResult Edit(ResearchPost postInfo)
 {
     rr.EditPost(postInfo);
     return(RedirectToAction("Index"));
 }
Beispiel #8
0
        public ActionResult Edit(Guid Id)
        {
            ResearchPost post = rr.GetPost(Id);

            return(View(post));
        }