public void InsertArtwork(Artwork artwork) { db.Entry(artwork.Artist).State = EntityState.Unchanged; db.Entry(artwork.Category).State = EntityState.Unchanged; db.Artworks.Add(artwork); db.SaveChanges(); }
public ActionResult UploadAttachment(int blogid, int attachmentid = 0) { string[] img = { ".jpg", ".png", ".gif" }; string[] video = { ".mp4" }; string[] audio = { ".mp3", ".wav", ".ogg" }; if (attachmentid != 0) { var attach = db.Attach.Find(attachmentid); FileInfo fi = new FileInfo(Server.MapPath(attach.Src)); fi.Delete(); HttpPostedFileBase NewPic = Request.Files["upload-file"]; string extend = NewPic.FileName.Substring(NewPic.FileName.LastIndexOf(".")).ToLower(); string Path = "/Files/" + Guid.NewGuid() + extend; if (img.Contains(extend)) { attach.TYPE = "img"; } else if (video.Contains(extend)) { attach.TYPE = "video"; } else if (audio.Contains(extend)) { attach.TYPE = "audio"; } NewPic.SaveAs(Server.MapPath(Path)); attach.Src = Path; db.Entry(attach); db.SaveChanges(); AddChangelog("EditAttachment", WebSecurity.CurrentUserId, blogid); } else { Attachment attach = new Attachment(); attach.BlogsId = blogid; HttpPostedFileBase NewPic = Request.Files["upload-file"]; string extend = NewPic.FileName.Substring(NewPic.FileName.LastIndexOf(".")).ToLower(); string Path = "/Files/" + Guid.NewGuid() + extend; if (img.Contains(extend)) { attach.TYPE = "img"; } else if (video.Contains(extend)) { attach.TYPE = "video"; } else if (audio.Contains(extend)) { attach.TYPE = "audio"; } NewPic.SaveAs(Server.MapPath(Path)); attach.Src = Path; db.Attach.Add(attach); db.SaveChanges(); AddChangelog("AddAttachment", WebSecurity.CurrentUserId, blogid); } return(RedirectToAction("Details", new { id = blogid })); }
public void clearCart() { int userid = WebSecurity.CurrentUserId; var user = db.Cart.First(c => c.UserId == userid); int next = user.next; while (next != 0) { CartItem item = db.CartItems.Find(next); next = item.next; db.CartItems.Remove(item); } user.next = 0; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); }
public void add(int id) { CartItem item = db.CartItems.Find(id); item.Number++; MvcApplication.CartItemNUM++; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); ReWriteCart(); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult UpAva(int scroll) { if (Request.Files[0].FileName != "") { var avatar = db.Avatars.Where(m => m.UserId == WebSecurity.CurrentUserId).ToList(); if (avatar.Count() == 0) { UserAvatar newavatar = new UserAvatar(); HttpPostedFileBase hpf = Request.Files[0]; string extend = hpf.FileName.Substring(hpf.FileName.LastIndexOf(".")); string path = "/Avatar/" + Guid.NewGuid() + extend; newavatar.UserId = WebSecurity.CurrentUserId; newavatar.imgSrc = path; db.Avatars.Add(newavatar); db.SaveChanges(); string filepath = Server.MapPath(path); hpf.SaveAs(filepath); } else { try { FileInfo fi = new FileInfo(Server.MapPath(avatar[0].imgSrc)); fi.Delete(); } catch (Exception) { } HttpPostedFileBase hpf = Request.Files[0]; string extend = hpf.FileName.Substring(hpf.FileName.LastIndexOf(".")); string path = "/Avatar/" + Guid.NewGuid() + extend; avatar[0].imgSrc = path; db.Entry(avatar[0]); db.SaveChanges(); string filepath = Server.MapPath(path); hpf.SaveAs(filepath); } } return(RedirectToAction("Manage", new { scroll = scroll })); }
public void InsertBid(Bid bid) { db.Entry(bid.Auction).State = EntityState.Unchanged; db.Bids.Add(bid); db.SaveChanges(); }
public void InsertAuction(Auction auction) { db.Entry(auction.Artwork).State = EntityState.Unchanged; db.Auctions.Add(auction); db.SaveChanges(); }