Пример #1
0
 public HttpResponseMessage GetProductsForCart(Guid? buyerId)
 {
     try
     {
         var cartService = new CartService();
         var products = cartService.GetAllCartProducts(buyerId);
         var response = Request.CreateResponse(HttpStatusCode.OK, products);
         return response;
     }
     catch (Exception e)
     {
         var error = Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
         return error;
     }
 }
Пример #2
0
 public HttpResponseMessage DeleteProductFromCart(Guid? id)
 {
     try
     {
         var cartService = new CartService();
         var product = cartService.DeleteProduct(id);
         var response = Request.CreateResponse(HttpStatusCode.OK, product);
         return response;
     }
     catch (Exception e)
     {
         var error = Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
         return error;
     }
 }
Пример #3
0
 public HttpResponseMessage AddProductToCart(CART product)
 {
     try
     {
         var cartService = new CartService();
         var id = cartService.AddProductInCart(product);
         var response = Request.CreateResponse(HttpStatusCode.OK, id);
         return response;
     }
     catch (Exception e)
     {
         var error = Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
         return error;
     }
 }
Пример #4
0
        public HttpResponseMessage AddOrder(List<ProductsInOrder> orp)
        {
            //ProductsInOrder pr1 = new ProductsInOrder();
            //pr1.BUYERID = new Guid("E6AB9AB0-0F18-405A-A4A2-610E52C18B7D");
            //pr1.QUANTITY = 2;
            //pr1.Price = 20;
            //pr1.PRODUCTID = new Guid("9869EA11-DC7F-4114-81E9-9779481DDC3A");
            //orp.Add(pr1);
            //ProductsInOrder pr2 = new ProductsInOrder();
            //pr2.BUYERID = new Guid("E6AB9AB0-0F18-405A-A4A2-610E52C18B7D");
            //pr2.QUANTITY = 2;
            //pr2.Price = 20;
            //pr2.PRODUCTID = new Guid("DE04F38F-D0D1-44FB-9B15-1738FF49C411");
            //orp.Add(pr2);
            //ProductsInOrder pr3 = new ProductsInOrder();
            //pr3.BUYERID = new Guid("E6AB9AB0-0F18-405A-A4A2-610E52C18B7D");
            //pr3.QUANTITY = 2;
            //pr3.Price = 20;
            //pr3.PRODUCTID = new Guid("51FD75B2-F819-4DE6-82F4-7C91C38D874D");
            //orp.Add(pr3);
            //ProductsInOrder pr4 = new ProductsInOrder();
            //pr4.BUYERID = new Guid("E6AB9AB0-0F18-405A-A4A2-610E52C18B7D");
            //pr4.QUANTITY = 2;
            //pr4.Price = 20;
            //pr4.PRODUCTID = new Guid("D12E7EC5-63E3-419D-B5A1-4EDFD34B5189");
            //orp.Add(pr4);
            Decimal total_price = 0;
            try
            {
                foreach (ProductsInOrder pr in orp)
                {
                    total_price = total_price + pr.Price;

                }

                var userService = new UserService();
                var user = userService.GetUserById(orp[0].BUYERID);
                if (user == null ||user.ID == null || user.ID == Guid.Empty)
                {
                    var error = Request.CreateResponse(HttpStatusCode.NoContent, "Buyer not valid");
                    return error;
                }
                ORDER or = new ORDER();
                or.BUYERID = (System.Guid)user.ID;
                or.ISACTIVE = true;
                or.PLACE = user.PLACE;
                or.CITY = user.CITY;
                or.STATE = user.STATE;
                or.TOTATPRICE = total_price;
                or.ISSERVICE = false;
                or.ORDERDATE = DateTime.Now;
                var orderid = new OrderService().AddNewOrder(or);
                if (orderid == null || orderid == Guid.Empty)
                {
                    var error = Request.CreateResponse(HttpStatusCode.NoContent, "Could not place order");
                    return error;
                }
                foreach (ProductsInOrder pr in orp)
                {
                    ORDERPRODUCT op = new ORDERPRODUCT();
                    op.ORDERID = orderid;
                    op.PRICE = pr.Price;
                    op.QUANTITY = pr.QUANTITY;
                    op.PRODUCTID = pr.PRODUCTID;
                    bool ret = new OrderService().AddNewProductOrder(op);
                    if (!ret)
                    {
                        var error = Request.CreateResponse(HttpStatusCode.NoContent, "Some Products not added");
                        return error;
                    }
                }
                List<CartProduct> cart = new CartService().GetAllCartProducts(or.BUYERID);
                foreach(CartProduct cp in cart)
                {
                    Boolean res = new CartService().DeleteProduct(cp.ID);
                    
                }
                var response = Request.CreateResponse(HttpStatusCode.OK, orderid);
                return response;
            }
            catch (Exception e)
            {
                var error = Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
                return error;
            }
        }