Ejemplo n.º 1
0
        public HttpResponseMessage PostPurchReqItem([FromBody] purchaseRequestItem item)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    var result = dbContext.purchaseRequestItems.Add(item);
                    dbContext.SaveChanges();

                    purchaseRequest reqObj      = dbContext.purchaseRequests.FirstOrDefault(i => i.requestId == item.requestId);
                    double          totalAmount = Convert.ToDouble((from p in dbContext.purchaseRequestItems
                                                                    where p.requestId == item.requestId
                                                                    group p by p.requestId into g
                                                                    select g.Sum(c => c.subTotal).Value).FirstOrDefault());
                    reqObj.totalAmount            = totalAmount;
                    dbContext.Entry(reqObj).State = System.Data.Entity.EntityState.Modified;
                    dbContext.SaveChanges();

                    HttpResponseMessage response = new HttpResponseMessage();
                    response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Item Added to Cart Succesfully" });
                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));
                }
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage DeleteCartItem([FromUri] string requestItemId, [FromUri] string requestId, [FromUri] string supplierId)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response = new HttpResponseMessage();
                    purchaseRequestItem itemObj  = dbContext.purchaseRequestItems.FirstOrDefault(i => i.requestItemId == requestItemId && i.requestId == requestId && i.supplierId == supplierId);
                    if (itemObj == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Item cannot be found" });
                    }
                    else
                    {
                        dbContext.purchaseRequestItems.Remove(itemObj);
                        dbContext.SaveChanges();

                        purchaseRequest reqObj      = dbContext.purchaseRequests.FirstOrDefault(i => i.requestId == requestId);
                        double          totalAmount = Convert.ToDouble((from p in dbContext.purchaseRequestItems
                                                                        where p.requestId == requestId
                                                                        group p by p.requestId into g
                                                                        select g.Sum(c => c.subTotal).Value).FirstOrDefault());
                        reqObj.totalAmount            = totalAmount;
                        dbContext.Entry(reqObj).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();

                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Item deleted successfully" });
                    }

                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));
                }
            }
        }