public ActionResult Add(pictures image, string post, string description) { string file = Path.GetFileNameWithoutExtension(image.imageFile.FileName); string extension = Path.GetExtension(image.imageFile.FileName); string filename = file + DateTime.Now.ToString("yymmssfff") + extension; using (imagesGalleryEntities db = new imagesGalleryEntities()) { pictures addpicture = new pictures(); try { addpicture.id = (from picture in db.pictures select picture.id).Max() + 1; } catch (System.InvalidOperationException ex) { addpicture.id = 0; }; addpicture.name = post; addpicture.description = description; addpicture.publication_date = DateTime.Now; var Ouser = (user)Session["User"]; addpicture.user_id = Ouser.id; addpicture.picture_path = "/img/userspictures/" + filename; filename = Path.Combine(Server.MapPath("~/img/userspictures/"), filename); image.imageFile.SaveAs(filename); db.pictures.Add(addpicture); db.SaveChanges(); } ModelState.Clear(); return(View()); }
public ActionResult signup(String nickname, String email, String password) { user adduser = new user(); using (imagesGalleryEntities db = new imagesGalleryEntities()) { try { adduser.id = (from user in db.user select user.id).Max() + 1; } catch (System.InvalidOperationException ex) { adduser.id = 0; } adduser.name = nickname; adduser.username = email; adduser.password = password; db.user.Add(adduser); db.SaveChanges(); Session["user"] = adduser; return(Redirect("~/Dashboard/index")); } return(View()); }
// GET: Dashboard public ActionResult Index() { user currentUser = (user)Session["user"]; List <PicturesTableViewModel> lst = null; using (imagesGalleryEntities db = new imagesGalleryEntities()) { try { lst = (from p in db.pictures where p.user_id == currentUser.id select new PicturesTableViewModel { id = p.id, name = p.name, description = p.description, user_id = p.user_id, picture_varchar = p.picture_path }).ToList(); return(View(lst)); } catch (System.NullReferenceException e) { return(Redirect("~/home")); } } }
public ActionResult Index(int pictureId) { PictureWithCommentsModel model = new PictureWithCommentsModel(); List <ComentsTableViewModel> allcomments = null; List <PicturesTableViewModel> thepicture = null; List <UserTableViewModel> UserInfo = null;; using (imagesGalleryEntities db = new imagesGalleryEntities()) { allcomments = (from c in db.comments join us in db.user on c.user_id equals us.id where c.picture_id == pictureId && c.parent_comment_id == null select new ComentsTableViewModel { id = c.id, comments = c.comment, data_coment = c.comment_date.ToString(), parent_id = c.parent_comment_id, username = us.name, pictureId = c.picture_id, }).ToList(); thepicture = (from p in db.pictures where p.id == pictureId select new PicturesTableViewModel { id = p.id, name = p.name, description = p.description, publicationDate = p.publication_date.ToString(), picture_varchar = p.picture_path, }).ToList(); UserInfo = (from u in db.user join p in db.pictures on u.id equals p.user_id select new UserTableViewModel { id = u.id, username = u.name, nickname = u.username, }).Distinct().ToList(); } getChildComments(ref allcomments, null, 0, pictureId); model.comments = allcomments; model.picture = thepicture; model.user = UserInfo; return(View(model)); }
public void getChildComments(ref List <ComentsTableViewModel> Comments, List <ComentsTableViewModel> ActualChilds, int position, int pictureId) { int i = 0; for (i = 0; i < Comments.Count; i++) { using (imagesGalleryEntities db = new imagesGalleryEntities()) { int id_parent = Comments.ElementAt(i).id; Comments.ElementAt(i).childComments = (from c in db.comments join us in db.user on c.user_id equals us.id where c.picture_id == pictureId && c.parent_comment_id == id_parent select new ComentsTableViewModel { id = c.id, comments = c.comment, data_coment = c.comment_date.ToString(), parent_id = c.parent_comment_id, username = us.name, pictureId = c.picture_id, }).ToList(); if (Comments.ElementAt(i).childComments.Count > 0) { for (int j = 0; j < Comments.ElementAt(i).childComments.Count; j++) { int id_parent_last_lvl = Comments.ElementAt(i).childComments.ElementAt(j).id; Comments.ElementAt(i).childComments.ElementAt(j).childComments = (from c in db.comments join us in db.user on c.user_id equals us.id where c.picture_id == pictureId && c.parent_comment_id == id_parent_last_lvl select new ComentsTableViewModel { id = c.id, comments = c.comment, data_coment = c.comment_date.ToString(), parent_id = c.parent_comment_id, username = us.name, pictureId = c.picture_id, }).ToList(); } } } } }
public ActionResult index(String username, String password) { ViewBag.Title = "Your contact page." + username + " y " + password; using (imagesGalleryEntities db = new imagesGalleryEntities()) { var lst = from d in db.user where d.username == username && d.password == password select d; if (lst.Count() == 1) { user Ouser = lst.First(); Session["user"] = Ouser; return(Redirect("~/Dashboard/index")); } else { } } return(View()); }
public async Task <List <ComentsTableViewModel> > loadComments(string CommentId, string pictureId) { List <ComentsTableViewModel> MoreComments = null; using (imagesGalleryEntities db = new imagesGalleryEntities()) { int CommentIdInt = Int32.Parse(CommentId); int PictureIdInt = Int32.Parse(pictureId); MoreComments = (from c in db.comments join us in db.user on c.user_id equals us.id where c.picture_id == PictureIdInt && c.parent_comment_id == CommentIdInt select new ComentsTableViewModel { id = c.id, comments = c.comment, data_coment = c.comment_date.ToString(), parent_id = c.parent_comment_id, username = us.name, pictureId = c.picture_id, }).ToList(); } return(MoreComments); }