public IHttpActionResult Get(int id) { var sellPosting = repo.Get(id); SellPosting s = sellPosting; if (sellPosting != null) { s.Links.Add(new Links() { HRef = "http://localhost:62832/api/SellPostings", Method = "GET", Rel = "Get all the user list" }); s.Links.Add(new Links() { HRef = "http://localhost:62832/api/SellPostings", Method = "POST", Rel = "Create a new user resource" }); s.Links.Add(new Links() { HRef = "http://localhost:62832/api/SellPostings/" + s.SellId, Method = "PUT", Rel = "Modify an existing user resource" }); s.Links.Add(new Links() { HRef = "http://localhost:62832/api/SellPostings/" + s.SellId, Method = "DELETE", Rel = "Delete an existing user resource" }); return(Ok(sellPosting)); } else { return(StatusCode(HttpStatusCode.NotFound)); } }
public SellPosting DeliveryInfo(int BookId) { SellPosting book = db.SellPostings.FirstOrDefault(x => x.BookId == BookId); SellPosting u = new SellPosting(); u.BookId = book.BookId; u.BuyerId = book.BuyerId; u.SellerId = book.SellerId; return(u); }
public IHttpActionResult Put([FromUri] int id, [FromBody] SellPosting sellPosting) { try { sellPosting.SellId = id; repo.Update(sellPosting); return(Ok(sellPosting)); } catch (Exception) { return(StatusCode(HttpStatusCode.BadRequest)); } }
public IHttpActionResult Post([FromBody] SellPosting sellPosting) { try { repo.Insert(sellPosting); string url = Url.Link("GetSellPostingId", new { id = sellPosting.SellId }); return(Created(url, sellPosting)); } catch (Exception e) { return(Ok(e.Message)); } }
public ActionResult History() { SellPosting sellPosting = bookRepo.getHistory(Convert.ToInt32(Session["Id"])); if (sellPosting != null) { return(View(sellPosting)); } else { return(View("CheckOut")); } }
public int DeliveredStatus(SellPostedModel model, int BookId) { SellPosting book = db.SellPostings.FirstOrDefault(x => x.BookId == BookId); book.Status = model.Status = 3; try { db.SaveChanges(); return(1); } catch { return(0); } }
public IHttpActionResult PutDelevery([FromUri] int sid, [FromBody] SellPosting sellPosting) { try { SellPostingRepo repo = new SellPostingRepo(); sellPosting.SellId = sid; repo.Update(sellPosting); return(Ok(sellPosting)); } catch (Exception) { return(StatusCode(HttpStatusCode.BadRequest)); } }
public void AddCheckOut(int id, int buyerId) { BookDetail b = db.BookDetails.SingleOrDefault(x => x.Id == id); SellPosting sellPosting = new SellPosting(); if (b != null) { sellPosting.BookId = b.Id; sellPosting.BuyerId = buyerId; sellPosting.offeredPoint = b.Point; sellPosting.SellerId = b.UserId; sellPosting.Status = 0; db.SellPostings.Add(sellPosting); db.SaveChanges(); } }
public ActionResult CheckOut() { SellPosting sellPosting = bookRepo.getCheckout(Convert.ToInt32(Session["id"])); if (sellPosting != null) { BookDetail bookDetail = bookRepo.getBookInfo(sellPosting.BookId); CheckOutViewModel checkOutView = new CheckOutViewModel(); checkOutView.BookTitle = bookDetail.Title; checkOutView.offeredPoint = sellPosting.offeredPoint; Session["SellId"] = bookDetail.Id; return(View(checkOutView)); } else { return(View()); } }
public void confirm(int id) { SellPosting sellPosting = db.SellPostings.FirstOrDefault(x => x.BookId == id); if (sellPosting != null) { sellPosting.Status = 1; db.SaveChanges(); } BookDetail bookDetail = db.BookDetails.FirstOrDefault(x => x.Id == id); if (bookDetail != null) { bookDetail.status = 4; db.SaveChanges(); } Login l = db.Logins.FirstOrDefault(x => x.id == sellPosting.BuyerId); UserDetail buyer = db.UserDetails.FirstOrDefault(x => x.email == l.email); if (buyer.point >= sellPosting.offeredPoint) { if (buyer != null) { buyer.point = buyer.point - sellPosting.offeredPoint; db.SaveChanges(); } Login l2 = db.Logins.FirstOrDefault(x => x.id == sellPosting.SellerId); UserDetail seller = db.UserDetails.FirstOrDefault(x => x.email == l2.email); if (seller != null) { seller.point = seller.point + sellPosting.offeredPoint; db.SaveChanges(); } } else { sellPosting.Status = 0; bookDetail.status = 1; db.SaveChanges(); } }
public int CreateSellpost(SellPostedModel model, int id) { SellPosting book = new SellPosting(); book.BookId = model.BookId; book.offeredPoint = model.offeredPoint; book.SellerId = model.SellerId; book.BuyerId = model.BuyerId; book.Status = model.Status; try { db.SellPostings.Add(book); db.SaveChanges(); return(1); } catch { return(0); } }
public SellPosting getHistory(int id) { SellPosting book = db.SellPostings.FirstOrDefault(x => x.BuyerId == id && x.Status >= 1); return(book); }
public SellPosting getCheckout(int id) { SellPosting book = db.SellPostings.FirstOrDefault(x => x.BuyerId == id && x.Status == 0); return(book); }