Beispiel #1
0
        public IProduct GetProduct(Guid id)
        {
            var product = _prodHandler.GetProduct(id);

            if (product.IsNew)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(product);
        }
        public Product GetProduct(string productName)
        {
            if (string.IsNullOrEmpty(productName))
            {
                throw  new ArgumentException();
            }

            return(_handler.GetProduct(productName));
        }
Beispiel #3
0
      public ActionResult Get()
      {
          if (productHandler.GetProduct() == null)
          {
              return(BadRequest(new { message = " There are no product to display" }));
          }

          return(Ok(this.productHandler.GetProduct()));
      }
Beispiel #4
0
        public IActionResult Getproduct(string Name)
        {
            var result = _productHandler.GetProduct(Name);

            if (result.HttpStatusCode == HttpStatusCode.InternalServerError)
            {
                return(new NotFoundResult());
            }
            return(new OkObjectResult(result));
        }
Beispiel #5
0
        public Results <ItemModel> AddItem(string productName, int Quantity)
        {
            if (string.IsNullOrWhiteSpace(productName))
            {
                return new Results <ItemModel>()
                       {
                           Exception      = "product doesn't match.",
                           HttpStatusCode = HttpStatusCode.BadRequest,
                           Result         = null,
                           Success        = false
                       }
            }
            ;
            var product = _handler.GetProduct(productName);

            if (product.Success == false)
            {
                return new Results <ItemModel>()
                       {
                           Exception      = "Product Not found.",
                           HttpStatusCode = HttpStatusCode.NotFound,
                           Result         = null,
                           Success        = false
                       }
            }
            ;
            if (product.Result.StockLevel < Quantity)
            {
                return new Results <ItemModel>()
                       {
                           Exception      = "we dont have enough Product",
                           HttpStatusCode = HttpStatusCode.OK,
                           Result         = null,
                           Success        = true
                       }
            }
            ;
            return(new Results <ItemModel>()
            {
                Exception = null,
                HttpStatusCode = HttpStatusCode.OK,
                Result = new ItemModel()
                {
                    Name = product.Result.ProductName,
                    Price = product.Result.Price,
                    Brand = product.Result.Brands.BrandName,
                    Id = product.Result.Id,
                    Quantity = Quantity,
                    TotalPrice = (double)product.Result.Price * Quantity
                },
                Success = true
            });
        }
    }
}
Beispiel #6
0
        public int Add(Guid id, int productid)
        {
            foreach (var item in productHandler.GetProduct())
            {
                if (item.ProductId == productid)
                {
                    CustomerCartList.Add(new Cart()
                    {
                        ProductId = item.ProductId, ProductName = item.ProductName, ProductCost = item.ProductCost, CustomerCartId = id
                    });

                    return(1);
                }
            }
            return(0);
        }
Beispiel #7
0
 public void Purchase(List <ItemModel> items, uint purchaseType, string user)
 {
     foreach (var item in items)
     {
         var product = _product.GetProduct(item.Name).Result;
         _balance.AddBalance(new Balance
         {
             Date          = DateTime.Now,
             PaymentTypeId = (int)purchaseType,
             ProductId     = product.Id,
             Quantity      = (uint)item.Quantity,
             Incoming      = product.Price * item.Quantity,
             Ammount       = _balance.GetLastBalance().Ammount + product.Price * item.Quantity,
             EmployerId    = user
         });
     }
 }
Beispiel #8
0
        public List <SaleProduct> GetProducts(List <ItemModel> items)
        {
            var products = new List <SaleProduct>();

            foreach (var item in items)
            {
                var check = _productHandler.GetProduct(item.Name).Result;
                products.Add(new SaleProduct
                {
                    BarCode      = check.BarCode,
                    ProductId    = check.Id,
                    ProductName  = check.ProductName,
                    Price        = check.Price,
                    StockLevel   = check.StockLevel,
                    OrderLevel   = check.OrderLevel,
                    CategoriesId = check.CategoriesId,
                    Category     = check.Categories.Name,
                    BrandId      = check.BrandId,
                    Brand        = check.Brands.BrandName,
                    SaleQuantity = item.Quantity
                });
            }
            return(products);
        }