示例#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 }));
                }
            }
        }
示例#2
0
        public HttpResponseMessage DeleteSupplier([FromUri] string id)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response    = new HttpResponseMessage();
                    supplier            supplierObj = dbContext.suppliers.Find(id);
                    if (supplierObj == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Supplier cannot be found" });
                    }
                    else
                    {
                        dbContext.suppliers.Remove(supplierObj);
                        dbContext.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Supplier deleted successfully" });
                    }

                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));;
                }
            }
        }
示例#3
0
        public HttpResponseMessage EditSupplierById([FromUri] string id, [FromBody] supplier supplier)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response    = new HttpResponseMessage();
                    supplier            supplierObj = dbContext.suppliers.Find(id);
                    if (supplierObj == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Supplier cannot be found" });
                    }
                    else
                    {
                        supplierObj.supplierId             = supplier.supplierId;
                        supplierObj.name                   = supplier.name;
                        supplierObj.address                = supplier.address;
                        supplierObj.contactNo              = supplier.contactNo;
                        supplierObj.email                  = supplier.email;
                        dbContext.Entry(supplierObj).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Supplier edited successfully" });
                    }

                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));;
                }
            }
        }
示例#4
0
        public HttpResponseMessage DeleteSupplier([FromUri] string supItemId, [FromUri] string supplierId)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response = new HttpResponseMessage();
                    supplier_items      itemObj  = dbContext.supplier_items.FirstOrDefault(i => i.supItemId == supItemId && i.supplierId == supplierId);
                    if (itemObj == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Item cannot be found" });
                    }
                    else
                    {
                        dbContext.supplier_items.Remove(itemObj);
                        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 }));;
                }
            }
        }
示例#5
0
        public HttpResponseMessage PostSupplier([FromBody] inventory item)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response = new HttpResponseMessage();
                    if (item.currentStock > item.maxStock)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Stock Exceeds and Item cannot be Saved" });
                    }
                    else
                    {
                        var result = dbContext.inventories.Add(item);
                        dbContext.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Item Added into Inventory Succesfully" });
                    }

                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));
                }
            }
        }
        public HttpResponseMessage EditSupplierById([FromUri] string id, [FromBody] siteManager siteManager)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response = new HttpResponseMessage();
                    siteManager         sManager = dbContext.siteManagers.Find(id);
                    if (sManager == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Site Manager cannot be found" });
                    }
                    else
                    {
                        sManager.smanagerNo    = siteManager.smanagerNo;
                        sManager.sname         = siteManager.sname;
                        sManager.snic          = siteManager.snic;
                        sManager.scontactNo    = siteManager.scontactNo;
                        sManager.site          = siteManager.site;
                        sManager.approvedValue = siteManager.approvedValue;

                        dbContext.Entry(sManager).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Site Manager edited successfully" });
                    }

                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));;
                }
            }
        }
        public HttpResponseMessage DeletePaymentById([FromUri] string id, [FromBody] payment payment)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response   = new HttpResponseMessage();
                    payment             paymentObj = dbContext.payments.Find(id);
                    if (paymentObj == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Payment cannot be found" });
                    }
                    else
                    {
                        paymentObj.status = "BLOCK";
                        dbContext.Entry(paymentObj).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Payments edited successfully" });
                    }

                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));;
                }
            }
        }
示例#8
0
        public HttpResponseMessage AprrovePurchReq([FromUri] string requestId, [FromBody] purchaseRequest reqObj)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response   = new HttpResponseMessage();
                    purchaseRequest     requestObj = dbContext.purchaseRequests.Find(requestId);
                    if (requestObj == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Purchase Request cannot be found" });
                    }
                    else
                    {
                        requestObj.requestStatus          = "OPEN";
                        dbContext.Entry(requestObj).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Purchase Request Approved successfully" });
                    }

                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));
                }
            }
        }
示例#9
0
        public HttpResponseMessage EditPurchaseById([FromUri] string id, [FromBody] order order)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response = new HttpResponseMessage();
                    order orderObj = dbContext.orders.Find(id);
                    if (orderObj == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Order cannot be found" });
                    }
                    else
                    {
                        orderObj.id       = order.id;
                        orderObj.reqId    = order.reqId;
                        orderObj.createBy = order.createBy;
                        orderObj.date     = order.date;
                        orderObj.status   = order.status;
                        dbContext.Entry(orderObj).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Order edited successfully" });
                    }

                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));;
                }
            }
        }
示例#10
0
 public HttpResponseMessage PostOrder(order order)
 {
     using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
     {
         try
         {
             var purchaseOrders = dbContext.orders.Add(order);
             dbContext.SaveChanges();
             purchaseRequest reqObj = dbContext.purchaseRequests.Find(order.reqId);
             reqObj.requestStatus = "CLOSE";
             dbContext.SaveChanges();
             HttpResponseMessage response = new HttpResponseMessage();
             response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Order Added Succesfully" });
             return(response);
         }
         catch (Exception e)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));;
         }
     }
 }
示例#11
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 }));
                }
            }
        }
示例#12
0
 public HttpResponseMessage PostSupplier([FromBody] supplier supplier)
 {
     using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
     {
         try
         {
             var suppliers = dbContext.suppliers.Add(supplier);
             dbContext.SaveChanges();
             HttpResponseMessage response = new HttpResponseMessage();
             response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Supplier Added Succesfully" });
             return(response);
         }
         catch (Exception e)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));;
         }
     }
 }
示例#13
0
 public HttpResponseMessage PostPurchaseRequest([FromBody] purchaseRequest req)
 {
     using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
     {
         try
         {
             var result = dbContext.purchaseRequests.Add(req);
             dbContext.SaveChanges();
             HttpResponseMessage response = new HttpResponseMessage();
             response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Purchase Request Added Succesfully" });
             return(response);
         }
         catch (Exception e)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));;
         }
     }
 }
示例#14
0
        public HttpResponseMessage PlaceOrder([FromUri] string requestId, [FromBody] purchaseRequest reqObj)
        {
            using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1())
            {
                try
                {
                    HttpResponseMessage response   = new HttpResponseMessage();
                    purchaseRequest     requestObj = dbContext.purchaseRequests.Find(requestId);
                    if (requestObj == null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Purchase Request cannot be found" });
                    }
                    else
                    {
                        double approvedValue = Convert.ToDouble((from p in dbContext.siteManagers
                                                                 where p.smanagerNo == reqObj.createdBy
                                                                 select(p.approvedValue).Value).FirstOrDefault());
                        if (reqObj.totalAmount > approvedValue)
                        {
                            requestObj.requestStatus = "NEED APPROVAL";
                        }
                        else
                        {
                            requestObj.requestStatus = reqObj.requestStatus;
                        }
                        dbContext.Entry(requestObj).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Purchase Request edited successfully" });
                    }

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