Ejemplo n.º 1
0
        public async Task <ShoppingResult> GetListById(int IdItem)
        {
            var result = new ShoppingResult();

            try
            {
                if (IdItem != 0)
                {
                    var resultList = _shoppingListDataAccess.GetListById(new Shopping()
                    {
                        IdItem = IdItem
                    });

                    if (resultList.Count > 0)
                    {
                        result.Data       = resultList;
                        result.ResultCode = ShoppingCodes.Success;
                    }
                    else
                    {
                        result.ResultCode = ShoppingCodes.NoContent;
                        result.Message    = "There's no record with this IdItem!";
                    }
                }
            }
            catch (Exception ex)
            {
                result.ResultCode = ShoppingCodes.InternalServerError;
                this._logger.LogError(ex, ex.Message);
                throw ex;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <ShoppingResult> CreateListItem(Shopping shopping)
        {
            var result = new ShoppingResult();

            try
            {
                if (!String.IsNullOrEmpty(shopping.Description))
                {
                    _shoppingListDataAccess.CreateListItem(shopping);
                    result.ResultCode = ShoppingCodes.Success;
                }
                else
                {
                    result.Message    = "There's no item";
                    result.ResultCode = ShoppingCodes.BadRequest;
                }
            }
            catch (Exception ex)
            {
                result.ResultCode = ShoppingCodes.InternalServerError;
                result.Message    = ex.Message;
                this._logger.LogError(ex, ex.Message);
                //throw ex;
            }

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <ShoppingResult> GetAll()
        {
            var result = new ShoppingResult();

            try
            {
                var resultList = _shoppingListDataAccess.GetAll();

                if (resultList != null)
                {
                    result.Data       = resultList;
                    result.ResultCode = ShoppingCodes.Success;
                }
                else
                {
                    result.ResultCode = ShoppingCodes.NoContent;
                }
            }
            catch (Exception ex)
            {
                result.ResultCode = ShoppingCodes.InternalServerError;
                this._logger.LogError(ex, ex.Message);
                throw ex;
            }
            return(result);
        }
Ejemplo n.º 4
0
        public async Task <ShoppingResult> DeleteListItem(Shopping shopping)
        {
            var result = new ShoppingResult();

            try
            {
                if (shopping != null)
                {
                    if (shopping.IdItem != 0)
                    {
                        _shoppingListDataAccess.Delete(shopping);
                        result.ResultCode = ShoppingCodes.Success;
                    }
                }
                else
                {
                    result.ResultCode = ShoppingCodes.BadRequest;
                }
            }
            catch (Exception ex)
            {
                result.ResultCode = ShoppingCodes.InternalServerError;
                this._logger.LogError(ex, ex.Message);
                throw ex;
            }
            return(result);
        }
Ejemplo n.º 5
0
 public IActionResult CompleteShopping(CompleteShopping completeShopping)
 {
     if (ModelState.IsValid)
     {
         ShoppingResult.Add(completeShopping);
         return(View("Thanks1", completeShopping));
     }
     return(View());
 }
Ejemplo n.º 6
0
 static Supply CreateSupplyObject(SupplyType type, ShoppingResult result)
 {
     return(new Supply
     {
         SupplyId = result.ProductId,
         Type = type,
         Name = result.Title,
         Vendor = result.Source,
         Price = result.ExtractedPrice,
         Link = result.Link,
         Thumbnail = result.Thumbnail
     });
 }
Ejemplo n.º 7
0
        public ShoppingResult Buy()
        {
            ShoppingResult result = cartItem.Compute();    //get the basic tax

            return(result);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddTransient <ITaxRateProvider, TaxRateProvider>()
                                  .AddTransient <BasicTaxFactory>()
                                  .AddTransient <ImportTaxFactory>()
                                  .AddTransient <TaxDetail>()
                                  .AddTransient <ShoppingResult>()
                                  .AddTransient <CartItem>()
                                  .AddTransient <Cart>()
                                  .BuildServiceProvider();

            //Create Item in run time for this demo

            Item[] items_1 = new Item[]
            {
                new Item(ItemType.Book, "Test Book1", 1, 12.49m, false),
                new Item(ItemType.Music, "Music CD", 1, 14.99m, false),
                new Item(ItemType.Food, "Chocolate", 1, 0.85m, false)
            };

            Item[] items_2 = new Item[]
            {
                new Item(ItemType.ImportedChocolate, "Test Book1", 1, 10.00m, true),
                new Item(ItemType.Perfume, "Music CD", 1, 47.50m, true)
            };

            Cart cart1 = serviceProvider.GetService <Cart>();

            Console.WriteLine("-------------------Input 1--------------------");
            cart1.AddItemToCart(items_1);

            ShoppingResult result_1 = cart1.Buy();

            result_1.ItemsBilled.ForEach(delegate(Item item)
            {
                Console.WriteLine("");
                Console.Write($"{item.Qty} {item.Name} at ${item.Price}");
                if (item.IsExempted())
                {
                    Console.Write($"(Exempted from tax)\n");
                }
            });

            Console.WriteLine("-------------------Ouput 1--------------------");

            Console.WriteLine($"Total Sales Tax: {result_1.TotalSalesTax}");
            Console.WriteLine($"Import Tax: {result_1.TotalImportTax}");
            Console.WriteLine($"Total: {result_1.Total}");

            Console.WriteLine("-------------------Input 2--------------------");


            Cart cart2 = serviceProvider.GetService <Cart>();

            cart2.AddItemToCart(items_2);
            ShoppingResult result_2 = cart2.Buy();

            foreach (var item in result_2.ItemsBilled)
            {
                Console.WriteLine($"{item.Qty} {item.Name} at ${item.Price}");
            }

            Console.WriteLine("-------------------Ouput 2--------------------");

            Console.WriteLine($"Total Sales Tax: {result_2.TotalSalesTax}");
            Console.WriteLine($"Import Tax: {result_2.TotalImportTax}");
            Console.WriteLine($"Total: {result_2.Total}");

            Console.ReadLine();
        }