public List <PostModel> getprofileposts(int profile_id) { using (CraftsEntities context = new CraftsEntities()) { List <PostModel> post = (from p in context.Posts_table where p.profile_id == profile_id orderby p.Post_id descending select new PostModel { Post_id = p.Post_id, Post_body = p.Post_body, Post_pic = p.Post_pic, Post_date = p.Post_date, User_id = p.User_table.User_Id, user_image = p.User_table.ProfilePicture, username = p.User_table.FName + " " + p.User_table.LName, commentsofpost = (from c in context.Comments_Table where c.Comment_postID == p.Post_id orderby c.Comment_Date descending select new CommentModel { Comment_id = c.Comment_id, Comment_Username = c.User_table.FName + " " + c.User_table.LName, Comment_body = c.Comment_body, Comment_Date = c.Comment_Date, Comment_profilePicture = c.User_table.ProfilePicture, Comment_UserID = c.User_table.User_Id }).ToList() }).ToList(); return(post); } }
public void Insertusercomments(string comment, int userid, int postid) { using (CraftsEntities context = new CraftsEntities()) { Comments_Table newpost = new Comments_Table { Comment_postID = postid, Comment_Date = DateTime.Now, Comment_body = comment, Comment_UserID = userid }; context.Comments_Table.Add(newpost); context.SaveChanges(); } }
public void InsertProductreview(string post, int userid) { using (CraftsEntities context = new CraftsEntities()) { ProductReview_table newpost = new ProductReview_table { review_date = DateTime.Now, review_body = post, user_id = userid }; context.ProductReview_table.Add(newpost); context.SaveChanges(); } }
public void Insertuserpost(string post, int userid) { using (CraftsEntities context = new CraftsEntities()) { Posts_table newpost = new Posts_table { Post_date = DateTime.Now, Post_body = post, User_id = userid, Post_pic = null }; context.Posts_table.Add(newpost); context.SaveChanges(); } }
public static List <CategoryModel> allcatigories() { using (CraftsEntities context = new CraftsEntities()) { var cat = (from c in context.Category_table select new CategoryModel { Cat_Name = c.Cat_Name, Cat_Id = c.Cat_Id }).ToList(); return(cat); } }
public List <ReviewModel> getproductposts(int pro_id) { using (CraftsEntities context = new CraftsEntities()) { List <ReviewModel> post = (from p in context.ProductReview_table where p.product_id == pro_id orderby p.review_id descending select new ReviewModel { review_id = p.review_id, review_body = p.review_body, User_id = p.User_table.User_Id, username = p.User_table.FName + " " + p.User_table.LName, user_image = p.User_table.ProfilePicture }).ToList(); return(post); } }
public bool checkout(int phone, string address) { bool success; CartModel Mycart = (CartModel)HttpContext.Current.Session["cart"]; using (CraftsEntities conn = new CraftsEntities()) { if (HttpContext.Current.Session["User_Id"] != null) { Order_table NewOrder = new Order_table(); NewOrder.Expected_Price = Mycart.OrderTotalPrice; NewOrder.User_Id = int.Parse(HttpContext.Current.Session["User_Id"].ToString()); NewOrder.Order_Date = DateTime.Now; NewOrder.Order_Phone = phone; NewOrder.Order_Address = address; NewOrder.status = "pending"; NewOrder.rating = 0; //add instances to context conn.Order_table.Add(NewOrder); for (int i = 0; i < Mycart.CartItem.Count; i++) { OrderDetails_table NewOrderItem = new OrderDetails_table(); NewOrderItem.Order_Id = NewOrder.Order_Id; NewOrderItem.Pro_Id = Mycart.CartItem[i].ProductData.Product_Id; NewOrderItem.Quantity = Mycart.CartItem[i].ProductQty; NewOrderItem.Approval = "pending"; NewOrderItem.rating = 0; conn.OrderDetails_table.Add(NewOrderItem); } conn.SaveChanges(); HttpContext.Current.Session["cart"] = null; HttpContext.Current.Session["count"] = 0; HttpContext.Current.Session["TotalPrice"] = 0; success = true; } else { success = false; } } return(success); }
public static List <ProductModel> outofstockProducts(int userid) { using (CraftsEntities context = new CraftsEntities()) { var pro = (from p in context.Product_table where p.Vendor_id == userid && p.State == "out of stock" join c in context.Category_table on p.Cat_id equals c.Cat_Id select new ProductModel { Image = p.Image, Product_Description = p.Product_Description, Product_Price = p.Product_Price, Catigory_name = c.Cat_Name, Product_Name = p.Product_Name, Product_Id = p.Product_Id }).ToList(); return(pro); } }
public List <CommentModel> getpostcomments(int postid) { using (CraftsEntities context = new CraftsEntities()) { List <CommentModel> comments = (from p in context.Comments_Table where p.Comment_postID == postid orderby p.Comment_id descending select new CommentModel { Comment_id = p.Comment_id, Comment_body = p.Comment_body, Comment_Date = p.Comment_Date, Comment_postID = p.Posts_table.Post_id, Comment_Username = p.User_table.FName + " " + p.User_table.LName, Comment_profilePicture = p.User_table.ProfilePicture, Comment_UserID = p.User_table.User_Id }).ToList(); return(comments); } }
public static void addnewproduct(ProductModel newproduct, string cat_name, int userid) { byte[] fileData = null; var binaryReader = new BinaryReader(newproduct.insertedimg.InputStream); fileData = binaryReader.ReadBytes(newproduct.insertedimg.ContentLength); using (CraftsEntities context = new CraftsEntities()) { var catid = int.Parse((from c in context.Category_table where c.Cat_Name == cat_name select c.Cat_Id).FirstOrDefault().ToString()); var pro = new Product_table { Product_Name = newproduct.Product_Name, Product_Description = newproduct.Product_Description, Product_Price = newproduct.Product_Price, Cat_id = catid, Image = fileData, Add_Date = DateTime.Now, Vendor_id = userid, State = "pending" }; context.Product_table.Add(pro); context.SaveChanges(); } }