示例#1
0
        // GET api/Myshelf
        public IList <myshelf> Getmyshelves()
        {
            //var myshelves = db.myshelves.Include(m => m.customer.customerid).Include(m => m.invoiceheader.invoiceheaderid).Include(m => m.product.productid);
            //return myshelves.AsEnumerable();
            ProductController productController = new ProductController();
            var x = (from m in db.myshelves
                     select new { myshelfid = m.myshelfid,
                                  purchasedate = m.purchasedate,
                                  enddate = m.enddate,
                                  purchasetype = m.purchasetype,
                                  rating = m.rating,
                                  customer_customerid = m.customer_customerid,
                                  invoiceheader_invoiceheaderid = m.invoiceheader_invoiceheaderid,
                                  product_productid = m.product_productid, });
            //var x = db.myshelves.ToList<myshelf>();
            IList <myshelf> l = new List <myshelf>();

            foreach (var a in x)
            {
                myshelf m = new myshelf();
                m.myshelfid                     = a.myshelfid;
                m.myshelfid                     = a.myshelfid;
                m.purchasedate                  = a.purchasedate;
                m.enddate                       = a.enddate;
                m.purchasetype                  = a.purchasetype;
                m.rating                        = a.rating;
                m.customer_customerid           = a.customer_customerid;
                m.invoiceheader_invoiceheaderid = a.invoiceheader_invoiceheaderid;
                m.product_productid             = a.product_productid;
                l.Add(m);
            }
            return(l);
        }
示例#2
0
        // PUT api/Myshelf/5
        public HttpResponseMessage Putmyshelf(short id, myshelf myshelf)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != myshelf.myshelfid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(myshelf).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
示例#3
0
        // DELETE api/Myshelf/5
        public HttpResponseMessage Deletemyshelf(short id)
        {
            myshelf myshelf = db.myshelves.Find(id);

            if (myshelf == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.myshelves.Remove(myshelf);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, myshelf));
        }
        // POST api/Invoiceheader
        public invoiceheader Postinvoiceheader(invoiceheader invoiceheader, myshelf myshelf, product product, string purchasetype, short days)
        {
            if (ModelState.IsValid)
            {
                db.invoiceheaders.Add(invoiceheader);

                db.SaveChanges();


                InvoicedetailController InvoicedetailController = new Controllers.InvoicedetailController();

                invoicedetail invoicedetail = new invoicedetail();
                invoicedetail.invoiceheader_invoiceheaderid = invoiceheader.invoiceheaderid;
                invoicedetail.product_productid             = myshelf.product_productid;

                if (purchasetype.Contains("rent"))
                {
                    invoicedetail.amount      = product.rentcost * days;
                    invoiceheader.totalamount = product.rentcost * days;
                }
                else
                {
                    invoicedetail.amount = Convert.ToInt32(product.price);
                }

                InvoicedetailController.Postinvoicedetail(invoicedetail, purchasetype);

                db.SaveChanges();
                // HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, invoiceheader);
                // response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = invoiceheader.invoiceheaderid }));
                return(invoiceheader);
            }
            else
            {
                return(invoiceheader);
                //return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
示例#5
0
        // GET api/Myshelf/5
        public List <myshelf> Getmyshelf(short cid, string purchasetype)
        {
            //List<myshelf> list = db.myshelves.ToList();
            var x = (from m in db.myshelves
                     select new
            {
                myshelfid = m.myshelfid,
                purchasedate = m.purchasedate,
                enddate = m.enddate,
                purchasetype = m.purchasetype,
                rating = m.rating,
                customer_customerid = m.customer_customerid,
                invoiceheader_invoiceheaderid = m.invoiceheader_invoiceheaderid,
                product_productid = m.product_productid
            });
            //var x = db.myshelves.ToList<myshelf>();
            IList <myshelf> list = new List <myshelf>();

            foreach (var a in x)
            {
                myshelf m = new myshelf();
                m.myshelfid                     = a.myshelfid;
                m.myshelfid                     = a.myshelfid;
                m.purchasedate                  = a.purchasedate;
                m.enddate                       = a.enddate;
                m.purchasetype                  = a.purchasetype;
                m.rating                        = a.rating;
                m.customer_customerid           = a.customer_customerid;
                m.invoiceheader_invoiceheaderid = a.invoiceheader_invoiceheaderid;
                m.product_productid             = a.product_productid;
                list.Add(m);
            }
            List <myshelf> myshelf = (from l in list where l.customer_customerid == cid select l).ToList <myshelf>();

            if (myshelf == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            if (purchasetype.Contains("purchase"))
            {
                List <myshelf> purchase = (from l in myshelf where l.purchasetype == "purchase" select l).ToList <myshelf>();

                return(purchase);
            }
            else if (purchasetype.Contains("rent"))
            {
                List <myshelf> rent = (from l in myshelf where l.purchasetype == "rent" select l).ToList <myshelf>();
                return(rent);
            }
            else if (purchasetype.Contains("lent"))
            {
                List <myshelf> lent = (from l in myshelf where l.purchasetype == "lent" select l).ToList <myshelf>();
                return(lent);
            }
            else
            {
                List <myshelf> cart = (from l in myshelf where l.purchasetype == "cart" select l).ToList <myshelf>();
                return(cart);
            }
        }