// 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);
            }
        }
Exemplo n.º 2
0
        //myshetlf add to cart receiving an array list
        public HttpResponseMessage Postmyshelf(short days, myshelf[] myshelfarr)
        {
            int    cnt         = 0;
            short  invheaderid = 0;
            double sumamt      = 0;

            if (ModelState.IsValid)
            {
                foreach (myshelf myshelf in myshelfarr)
                {
                    ProductController ProductController = new Controllers.ProductController();
                    product           product           = ProductController.Getproduct(myshelf.product_productid);
                    sumamt = sumamt + product.price;
                }
                foreach (myshelf myshelf in myshelfarr)
                {
                    myshelf.purchasedate = DateTime.Now;


                    if (myshelf.purchasetype.Equals("purchase"))
                    {
                        myshelf.enddate = null;

                        // myshelf.enddate = Convert.ToDateTime(999912312);
                    }
                    else
                    {
                        myshelf.enddate = myshelf.purchasedate.Value.AddDays(days);
                    }


                    ProductController ProductController = new Controllers.ProductController();
                    product           product           = ProductController.Getproduct(myshelf.product_productid);

                    if (cnt == 0)
                    {
                        InvoiceheaderController InvoiceheaderController = new InvoiceheaderController();
                        invoiceheader           invoiceheader           = new Models.invoiceheader();

                        invoiceheader.date                = DateTime.Now;
                        invoiceheader.totalamount         = sumamt;
                        invoiceheader.customer_customerid = myshelf.customer_customerid;

                        invoiceheader = InvoiceheaderController.Postinvoiceheader(invoiceheader, myshelf, product, myshelf.purchasetype, days);
                        myshelf.invoiceheader_invoiceheaderid = invoiceheader.invoiceheaderid;
                        invheaderid = invoiceheader.invoiceheaderid;
                        myshelf.invoiceheader_invoiceheaderid = invoiceheader.invoiceheaderid;

                        cnt++;
                        db.myshelves.Add(myshelf);


                        db.SaveChanges();
                    }
                    else
                    {
                        InvoicedetailController InvoicedetailController = new Controllers.InvoicedetailController();

                        invoicedetail invoicedetail = new invoicedetail();
                        invoicedetail.invoiceheader_invoiceheaderid = invheaderid;
                        invoicedetail.product_productid             = myshelf.product_productid;
                        invoicedetail.amount = product.price;

                        InvoicedetailController.Postinvoicedetail(invoicedetail, myshelf.purchasetype);
                        myshelf.invoiceheader_invoiceheaderid = invheaderid;

                        db.myshelves.Add(myshelf);
                        db.SaveChanges();
                    }
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, myshelfarr);
                return(response);
            }


            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }