Esempio n. 1
0
        public async Task <SaleProductsResponse> UpdateAsync(int id, SaleProducts product)
        {
            var existingProduct = await _saleProductRepository.GetById(id);

            if (existingProduct == null)
            {
                return(new SaleProductsResponse("was not found."));
            }

            existingProduct.ProductID       = product.ProductID;
            existingProduct.SaleID          = product.SaleID;
            existingProduct.ProductQuantity = product.ProductQuantity;

            try
            {
                _saleProductRepository.Update(existingProduct);
                await _unitOfWork.CompleteAsync();

                return(new SaleProductsResponse(existingProduct));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaleProductsResponse($"An error occurred when updating the SaleProduct: {ex.Message}"));
            }
        }
Esempio n. 2
0
        public override void DelOne(int id)
        {
            var productList = DbSetContext.Include(x => x.Products)
                              .Where(y => y.Codigo == id)
                              .AsNoTracking().ToList();

            foreach (var item in productList[0].Products)
            {
                SaleProducts saleProducts = new SaleProducts()
                {
                    CodigoSale    = id,
                    CodigoProduct = item.CodigoProduct
                };

                DbSet <SaleProducts> DbSetAux;

                DbSetAux = Db.Set <SaleProducts>();
                DbSetAux.Attach(saleProducts);
                DbSetAux.Remove(saleProducts);
                Db.SaveChanges();
            }


            base.DelOne(id);
        }
Esempio n. 3
0
        private async void UpdateSale()
        {
            var sale             = _saleManager.GetByID(SaleID);
            var updateSaleResult = await _saleManager.UpdateSale(new Sale()
            {
                AmountPaid     = Convert.ToDouble(textBox1.Text),
                Change         = Convert.ToDouble(Convert.ToDecimal(textBox1.Text) - Total),
                DateCreated    = sale.DateCreated,
                DateTime       = sale.DateTime,
                IsDeleted      = false,
                StoreID        = sale.StoreID,
                Total          = Convert.ToDecimal(Total),
                UserCreatedID  = sale.UserCreatedID,
                UserID         = sale.UserID,
                DateModified   = DateTime.Now,
                SaleID         = sale.SaleID,
                UserModifiedID = Global.User.UserID
            });

            if (updateSaleResult.IsSuccess)
            {
                SaleProducts = SaleProducts.Select(m =>
                {
                    m.SaleID = sale.SaleID;
                    return(m);
                }).ToList();

                //update saleproducts
                //bawasan quantity ng dapat bawasan
                //dagdagan ang dapat dagdagan
                updateSaleResult = await _saleManager.UpdateSaleProduct(SaleProducts, SaleID);
            }

            if (updateSaleResult.IsSuccess)
            {
                //bawasan quantity sa store
                await _storeManager.DecreaseProductLeft(Global.Store.StoreID, SaleProducts);

                Close();
                TransactionDone = true;
            }
            else
            {
                //delete sale by id
                //delete saleproduct by saleid
                await _saleManager.DeleteSale(SaleID);

                await _saleManager.DeleteSaleProductBySaleID(SaleID);

                MessageBox.Show("An error occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        private async void AddSale()
        {
            int insertedSaleID   = 0;
            var insertSaleResult = await _saleManager.AddSale(new Sale()
            {
                AmountPaid    = Convert.ToDouble(textBox1.Text),
                Change        = Convert.ToDouble(Convert.ToDecimal(textBox1.Text) - Total),
                DateCreated   = DateTime.Now,
                DateTime      = DateTime.Now,
                IsDeleted     = false,
                StoreID       = Global.Store.StoreID,
                Total         = Convert.ToDecimal(Total),
                UserCreatedID = Global.User.UserID,
                UserID        = Global.User.UserID
            });

            insertedSaleID = insertSaleResult.ID;

            if (insertSaleResult.IsSuccess)
            {
                SaleProducts = SaleProducts.Select(m =>
                {
                    m.SaleID = insertSaleResult.ID;
                    return(m);
                }).ToList();

                foreach (var saleProduct in SaleProducts)
                {
                    insertSaleResult = await _saleManager.AddSaleProduct(saleProduct);
                }
            }

            if (insertSaleResult.IsSuccess)
            {
                //bawasan quantity sa store
                await _storeManager.DecreaseProductLeft(Global.Store.StoreID, SaleProducts);

                Close();
                TransactionDone = true;
            }
            else
            {
                //delete sale by id
                //delete saleproduct by saleid
                await _saleManager.DeleteSale(insertedSaleID);

                await _saleManager.DeleteSaleProductBySaleID(insertedSaleID);

                MessageBox.Show("An error occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 5
0
        public async Task <SaleProductsResponse> DeleteAsync(SaleProducts saleProduct)
        {
            if (_saleProductRepository.GetById(saleProduct.ID) == null)
            {
                return(new SaleProductsResponse("Object With Specific ID Was Null"));
            }

            try
            {
                _saleProductRepository.Delete(saleProduct);
                await _unitOfWork.CompleteAsync();

                return(new SaleProductsResponse(saleProduct));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaleProductsResponse($"An error occurred when deleting the SaleProduct: {ex.Message}"));
            }
        }
        public int orderShowed(int id)
        {
            SaleProducts rez = ctx.saleProductBll.getOne(id);

            if (ModelState.IsValid)
            {
                rez.status = false;
                bool result = ctx.saleProductBll.add(rez);



                if (result)
                {
                    return(1);
                }

                return(0);
            }
            return(0);
        }
Esempio n. 7
0
        private void addProductToList(ProductModel model, string quantity)
        {
            bool found = false;
            int  int_quantity;

            try { int_quantity = Convert.ToInt32(quantity); }
            catch (Exception) { int_quantity = 1; }
            ObservableCollection <SaleProductModel> temp_list = new ObservableCollection <SaleProductModel>();

            foreach (SaleProductModel sp_model in SaleProducts)
            {
                temp_list.Add(sp_model);
            }
            for (int i = 0; i < temp_list.Count; i++)
            {
                if (temp_list[i].ProductID.value == model.ID.value && temp_list[i].Discount.value == 0)
                {
                    SaleProductModel temp_model = temp_list[i];
                    SaleProducts.Remove(temp_list[i]);
                    temp_model.Qunatity.value = int_quantity;
                    temp_model.SubTotal.value = temp_model.Price.value * temp_model.Qunatity.value;
                    SaleProducts.Insert(i, temp_model);
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                SaleProductModel sale_product_model = new SaleProductModel();
                sale_product_model.ProductName.value = model.Name.value;
                sale_product_model.ProductID.value   = model.ID.value;
                sale_product_model.Qunatity.value    = int_quantity;
                sale_product_model.Price.value       = model.Price.value;
                sale_product_model.SubTotal.value    = model.Price.value * sale_product_model.Qunatity.value;
                SaleProducts.Add(sale_product_model);
            }
            SearchedModel = null;
            calculateTotal();
        }
Esempio n. 8
0
        public async Task <SaleProductsResponse> InsertAsync(SaleProducts product)
        {
            try
            {
                var existingProduct = await _saleProductRepository.GetById(product.ID);

                if (existingProduct != null)
                {
                    return(new SaleProductsResponse("Invalid SaleProduct."));
                }

                await _saleProductRepository.Insert(product);

                await _unitOfWork.CompleteAsync();

                return(new SaleProductsResponse(product));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaleProductsResponse($"An error occurred when saving the SaleProduct: {ex.Message}"));
            }
        }
 public bool update(SaleProducts SaleProducts)
 {
     return(_saleProductDal.update(SaleProducts));
 }
 public bool add(SaleProducts SaleProducts)
 {
     return(_saleProductDal.add(SaleProducts));
 }
Esempio n. 11
0
 public bool IsValid()
 {
     return(SaleProducts.Any());
 }
Esempio n. 12
0
 public void RemoveSaleProduct(SaleProduct saleProduct)
 {
     SaleProducts.Remove(saleProduct);
 }
Esempio n. 13
0
 public void AddSaleProduct(SaleProduct saleProduct)
 {
     SaleProducts.Add(saleProduct);
 }
Esempio n. 14
0
 private void deleteItem(object parameter)
 {
     SaleProducts.Remove(SelectedItem);
     calculateTotal();
 }
        public ActionResult checkout(Bills bill)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (Request.IsAuthenticated)
                    {
                        Guid orderCode = Guid.NewGuid();

                        card card = (card)HttpContext.Session["activeBasket"];
                        if (card != null)
                        {
                            bill.orderCode = orderCode;

                            bill.billDate = DateTime.Now;

                            bill.totalPrice = card.cardTotalPrice;
                            bill.status     = true;
                            ctx.billBll.add(bill);
                            SaleProducts sale = new SaleProducts
                            {
                                customerID  = ctx.userBll.getOneByEmail(User.Identity.Name).id,
                                date        = DateTime.Now,
                                totalAmount = card.cardTotalPrice,
                                payType     = bill.payType,
                                billID      = bill.id,
                                status      = true,
                                orderCode   = orderCode,
                                description = bill.description,
                                orderDate   = bill.orderDate
                            };

                            ctx.saleProductBll.add(sale);


                            foreach (var item in card.BasketItems)
                            {
                                SaleProductsDetails details = new SaleProductsDetails
                                {
                                    productID    = item.products.id,
                                    count        = item.count,
                                    productPrice = (decimal)item.products.price,
                                    amount       = item.totalPrice,
                                    SaleID       = sale.id,
                                    tax          = card.tax
                                };
                                ctx.saleProductsDetailBll.add(details);
                            }


                            HttpContext.Session["activeBasket"] = null;
                        }
                        return(RedirectToAction("success", "basket", new { orderCode = orderCode }));
                    }
                    else
                    {
                        return(RedirectToAction("login", "users"));
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("_error", e.Message));
            }
        }