public ActionResult Index() { er.ClearUnreadPosts(User.Identity.GetUserId()); EducationBlogViewModel model = new EducationBlogViewModel(); model.Posts = er.GetAll().ToList(); foreach (var post in model.Posts) { EducationPostFileCombo rpfc = new EducationPostFileCombo() { AttatchedPost = post }; using (DataContext context = new DataContext()) { EducationPost rp = new EducationPost(); var EducationPostId = context.EducationPosts.Select(r => r.Id); var categoryFiles = context.UserFiles.Where(x => EducationPostId.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 ActionResult Create(EducationBlogViewModel model) { model.Post.Date = DateTime.Now; model.Post.UserId = User.Identity.GetUserId(); er.AddPost(model.Post); if (model.uploadFiles[0] != null) //Den skickar alltid med någon jävel { foreach (var file in model.uploadFiles) //Kontrollera så att alla filer är under 15MB { if (file.ContentLength > 15728640) //15MB i Bytes { ViewBag.Eeror = file.FileName + " är för stor. Storlek: " + (file.ContentLength / 1024).ToString() + "KB";; return(View(model)); } } UploadFile(model.uploadFiles, model.Post); } return(RedirectToAction("index")); }