public int AddSales(AddShoppingBasketRequest addShoppingBasketRequest)
        {
            using (DataAccess dataAccess = new DataAccess())
            {
                var shoppinglist = dataAccess.ShoppingBasket.Where(x => x.CustomerID == addShoppingBasketRequest.CustomerID).ToList();

                foreach (var item in shoppinglist)
                {
                    var seller = (from s in dataAccess.ShoppingBasket
                                  join p in dataAccess.Products on s.ProductID equals p.ProductID
                                  join sel in dataAccess.Sellers on p.SellerID equals sel.SellerID
                                  where p.ProductID == item.ProductID
                                  select new
                    {
                        Name = sel.Name,
                        Surname = sel.Surname,
                        Email = sel.Email
                    }).ToList()[0];

                    AddSalesRequest addSales = new AddSalesRequest();
                    addSales.CustomerID    = addShoppingBasketRequest.CustomerID;
                    addSales.SellerName    = seller.Name;
                    addSales.SellerSurname = seller.Surname;
                    addSales.SellerEmail   = seller.Email;
                    addSales.ProductID     = item.ProductID;
                    addSales.SalesNumber   = item.SalesNumber;
                    addSales.Cost          = item.Cost;
                    salesService.AddSales(addSales);
                    dataAccess.SaveChanges();
                    ClearAllShoppingList(new Contracts.Request.ShoppingBasket.ClearAllShoppingList(addShoppingBasketRequest.CustomerID));
                }
                return(dataAccess.SaveChanges());
            }
        }
Beispiel #2
0
        public ActionResult New(SalesViewModel model)
        {
            Sale sale = new Sale();

            Mapper.Map(model, sale);
            if (ModelState.IsValid)
            {
                _sales.AddSales(sale);
            }

            return(RedirectToAction("Index"));
        }
 public IActionResult AddSales([FromBody] MvSales sales)
 {
     try
     {
         dynamic jsonString = _salesService.AddSales(sales);
         return(Ok(jsonString));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #4
0
 public int AddSales(SalesViewModel salesViewModel)
 {
     if (salesViewModel != null)
     {
         SalesDTO salesDto = Mapper.Map <SalesDTO>(salesViewModel);
         int      id       = _salesService.AddSales(salesDto);
         return(id);
     }
     else
     {
         return(0);
     }
 }
 public IActionResult AddSales([FromBody] MvSales sales)
 {
     try
     {
         var added = _salesService.AddSales(sales);
         if (!added)
         {
             return(BadRequest());
         }
         return(Ok());
     }
     catch (Exception e)
     {
         throw e;
     }
 }