private void add(ProductSellByWeight productSellByWeight)
 {
     if (productSellByWeight != null)
     {
         ProductSell existingProductSell = productSellList.SingleOrDefault(productSell => productSell.productId == productSellByWeight.productId);
         if (existingProductSell == null)
         {
             productSellList.Add(productSellByWeight as ProductSell);
         }
         else
         {
             if (!existingProductSell.productName.Equals(productSellByWeight.productName))
             {
                 throw new ArgumentException("There is a conflict on the given productName");
             }
             else if (existingProductSell.unitPrice != productSellByWeight.unitPrice)
             {
                 throw new ArgumentException("There is a conflict on the given unitPrice");
             }
             else
             {
                 ((ProductSellByWeight)existingProductSell).addWeight(productSellByWeight.weight);
             }
         }
     }
     else
     {
         throw new ArgumentNullException("ProductSellByWeight");
     }
 }
 public virtual void add(ProductSell productSell)
 {
     if (productSell != null)
     {
         if (verifyProductSell(productSell))
         {
             if (productSell is ProductSellByQuantity)
             {
                 add(productSell as ProductSellByQuantity);
             }
             else if (productSell is ProductSellByWeight)
             {
                 add(productSell as ProductSellByWeight);
             }
             else
             {
                 throw new InvalidOperationException();
             }
         }
         else
         {
             throw new ArgumentOutOfRangeException("productSell does not contain valid attributes");
         }
     }
     else
     {
         throw new ArgumentNullException("productSell");
     }
 }
        public int Insert(ProductSell info, List <ProductSellRecord> records)
        {
            try
            {
                //string commandText = @"insert into Users(userName,userPassword,userLevel,userPhone,userAddress) values (
                //?userName,?userPassword,?userLevel,?userPhone,?userAddress)";

                string commandText = string.Format("insert into ProductSell(name, sellTime, comment, status, customerID) values('{0}', '{1}', '{2}', '{3}', {4})", info.Name, info.SellTime, info.Comment, info.Status, info.CustomerID);

                DbHelperAccess.executeNonQuery(commandText);

                int ProductSellID = DbHelperAccess.executeMax("ID", "ProductSell");

                ProductSellRecordDao dao = new ProductSellRecordDao();
                foreach (ProductSellRecord record in records)
                {
                    record.SellID = ProductSellID;
                    dao.Insert(record);
                }
                return(ProductSellID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 private void add(ProductSellByQuantity productSellByQuantity)
 {
     if (productSellByQuantity != null)
     {
         ProductSell existingProductSell = productSellList.SingleOrDefault(productSell => productSell.productId == productSellByQuantity.productId);
         if (existingProductSell == null)
         {
             productSellList.Add(productSellByQuantity as ProductSell);
         }
         else
         {
             if (!existingProductSell.productName.Equals(productSellByQuantity.productName))
             {
                 throw new ArgumentException("There is a conflict on the given productName");
             }
             else if (existingProductSell.unitPrice != productSellByQuantity.unitPrice)
             {
                 throw new ArgumentException("There is a conflict on the given unitPrice");
             }
             else
             {
                 ((ProductSellByQuantity)existingProductSell).addQuantity(productSellByQuantity.quantity);
             }
         }
     }
     else
     {
         throw new ArgumentNullException("ProductSellByQuantity");
     }
 }
Exemple #5
0
 public FormSell()
 {
     InitializeComponent();
     printPreviewDialog1.Document = printDocument1;
     productSell              = new ProductSell();
     dtpSellDate.Format       = DateTimePickerFormat.Custom;
     dtpSellDate.CustomFormat = "dd/MM/yyyy";
 }
Exemple #6
0
 public FormSell()
 {
     InitializeComponent();
     printPreviewDialog1.Document = printDocument1;
     productSell = new ProductSell();
     dtpSellDate.Format = DateTimePickerFormat.Custom;
     dtpSellDate.CustomFormat = "dd/MM/yyyy";
 }
        public async Task <ActionResult <ProductSellDto> > AddProduct([FromBody] ProductSell productSell)
        {
            await _repository.AddProductAsync(productSell);

            await _repository.CommitAsync();

            return(CreatedAtAction(nameof(GetProduct),
                                   new { productId = productSell.ProductId },
                                   productSell.Adapt <ProductSellDto> ()));
        }
Exemple #8
0
        public static ProductSell GetReleasedProductSell()
        {
            var discount    = Builder.GetProducePrice(1, 30, 0);
            var combination = Builder.GetBaseCombination();

            combination.SetProductDiscountAndPrice(discount);
            var productSell = ProductSell.GetProductSell(10);

            productSell.AddProductCombination(combination);
            productSell.ReleaseProductSell();
            return(productSell);
        }
        public async Task <ActionResult <ProductSellDto> > UpdateProduct([FromBody] ProductSell productSell)
        {
            var product = await _repository.UpdateProductAsync(productSell);

            if (product == null)
            {
                return(NotFound());
            }

            await _repository.CommitAsync();

            return(product);
        }
Exemple #10
0
        public void Cannot_AddDuplicateProductCombination()
        {
            var combination = Builder.GetProductCombination(new[] { "name1", "name2" }, new[] { "value1", "value2" });
            var discount    = Builder.GetProducePrice(1, 30, 0);

            combination.SetProductDiscountAndPrice(discount);
            var productSell = ProductSell.GetProductSell(10);

            productSell.AddProductCombination(combination);

            productSell.Invoking(x => x.AddProductCombination(combination))
            .Should().Throw <DomainException>().Where(e => e.Message.Contains(ProductSell.Reasons.DUPLICATE));
        }
        private async Task <ResponseMessagesDto> CreateProductSellAsync(CreateProductSaleDto productSellDto)
        {
            var productList = new List <ProductSell>();

            for (var x = 0; x < productSellDto.Quantity; x++)
            {
                var product = new ProductSell();
                product.Status        = productSellDto.Status;
                product.Description   = productSellDto.Description;
                product.SellingRate   = productSellDto.SellingRate;
                product.ShopProductId = productSellDto.ShopProductId;
                product.TenantId      = productSellDto.TenantId;
                productList.Add(product);
            }
            await _productSaleRepository.GetDbContext().AddRangeAsync(productList);

            //var result = await _productSaleRepository.InsertAsync(new ProductSell()
            //{
            //    Status = productSellDto.Status,
            //    SellingRate = productSellDto.SellingRate,
            //    ShopProductId = productSellDto.ShopProductId,
            //});


            await UnitOfWorkManager.Current.SaveChangesAsync();

            var shopProduct = await _shopProductRepository.GetAll()
                              .Where(i => i.Id == productSellDto.ShopProductId && i.Quantity > 0)
                              .SingleOrDefaultAsync();

            shopProduct.Quantity = shopProduct.Quantity - productSellDto.Quantity;
            await _shopProductRepository.UpdateAsync(shopProduct);

            if (productList[0].Id != 0)
            {
                return(new ResponseMessagesDto()
                {
                    Id = productList[0].Id,
                    SuccessMessage = AppConsts.SuccessfullyInserted,
                    Success = true,
                    Error = false,
                });
            }
            return(new ResponseMessagesDto()
            {
                Id = 0,
                ErrorMessage = AppConsts.InsertFailure,
                Success = false,
                Error = true,
            });
        }
        public async Task <ProductSellDto> UpdateProductAsync(ProductSell productSell)
        {
            var product = await _context.Set <ProductSell> ()
                          .FirstOrDefaultAsync(p => p.ProductId == productSell.ProductId);

            if (product != null)
            {
                product.ProductName   = productSell.ProductName;
                product.Specification = productSell.Specification;
                product.CategoryId    = productSell.CategoryId;
            }

            return(product.Adapt <ProductSellDto> ());
        }
        public void Update(ProductSell info, List <ProductSellRecord> records)
        {
            string commandText = string.Format("update ProductSell set name='{0}', sellTime='{1}', comment='{2}', customerID='{3}' where ID={4}",
                                               info.Name, info.SellTime, info.Comment, info.CustomerID, info.ID);

            DbHelperAccess.executeNonQuery(commandText);

            ProductSellRecordDao.getInstance().DeleteBySellID(info.ID);

            foreach (ProductSellRecord record in records)
            {
                record.SellID = info.ID;
                ProductSellRecordDao.getInstance().Insert(record);
            }
        }
        public bool IsProductSellReleasable(ProductSell productSell, Product product)
        {
            foreach (var productComibination in productSell.Combinations)
            {
                var containsAllAttrbs =
                    _productCombinationValidator.EnsureCombinationContainsAllAttributes(productComibination, product);
                var containsValidOptions =
                    _productCombinationValidator.EnsureCombinationContainsValidOptions(productComibination, product);

                if (!(containsAllAttrbs && containsValidOptions))
                {
                    return(false);
                }
            }
            return(true);
        }
        public ProductSell FindByID(int ID)
        {
            string      commandText = string.Format("select * from ProductSell where ID={0}", ID);
            DataRow     dr          = DbHelperAccess.executeQueryGetOneRow(commandText);
            ProductSell sell        = new ProductSell();

            if (dr != null)
            {
                sell.ID         = (int)dr["ID"];
                sell.Name       = dr["name"] as string;
                sell.SellTime   = (DateTime)dr["sellTime"];
                sell.Comment    = dr["comment"] as string;
                sell.Status     = (int)dr["status"];
                sell.CustomerID = (int)dr["customerID"];
                return(sell);
            }
            return(null);
        }
 private bool verifyProductSell(ProductSell productSell)
 {
     if (productSell.productId < 1)
     {
         return(false);
     }
     else if (!(productSell.unitPrice > 0))
     {
         return(false);
     }
     else if (!(productSell.getPrice() > 0))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        public async Task <IActionResult> Create([Bind("Id,ProductTypeId,ProductName,ProductQualityId,Price,AmountSignId,NumberOfProduct,NumberSignId,TotalPrice,PaymentMethodId,Condition,ManagerSignature,EntryDate")] ProductSell productSell)
        {
            if (ModelState.IsValid)
            {
                productSell.TotalPrice = productSell.Price * productSell.NumberOfProduct;

                productSell.ManagerSignature = HttpContext.Session.GetString("username");

                productSell.EntryDate = DateTime.Now;

                _context.Add(productSell);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AmountSignId"]     = new SelectList(_context.AmountSign, "AmountSignId", "AmountSignName", productSell.AmountSignId);
            ViewData["NumberSignId"]     = new SelectList(_context.NumberSign, "NumberSignId", "NumberSignName", productSell.NumberSignId);
            ViewData["PaymentMethodId"]  = new SelectList(_context.PaymentMethod, "PaymentMethodId", "PaymentMethodName", productSell.PaymentMethodId);
            ViewData["ProductQualityId"] = new SelectList(_context.ProductQuality, "ProductQualityId", "ProductQualityName", productSell.ProductQualityId);
            ViewData["ProductTypeId"]    = new SelectList(_context.Set <ProductType>(), "ProductTypeId", "ProductTypeName", productSell.ProductTypeId);
            return(View(productSell));
        }
 public virtual void remove(ProductSell giveProductSell)
 {
     if (giveProductSell != null)
     {
         if (verifyProductSell(giveProductSell))
         {
             ProductSell existingProductSell = productSellList.SingleOrDefault(productSell => productSell.productId == giveProductSell.productId);
             if (existingProductSell != null)
             {
                 productSellList.Remove(existingProductSell);
             }
         }
         else
         {
             throw new ArgumentOutOfRangeException("productSell does not contain valid attributes");
         }
     }
     else
     {
         throw new ArgumentNullException("productSell");
     }
 }
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProductTypeId,ProductName,ProductQualityId,Price,AmountSignId,NumberOfProduct,NumberSignId,TotalPrice,PaymentMethodId,Condition,ManagerSignature,EntryDate")] ProductSell productSell)
        {
            if (id != productSell.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    productSell.TotalPrice = productSell.Price * productSell.NumberOfProduct;

                    productSell.ManagerSignature = HttpContext.Session.GetString("username");


                    _context.Update(productSell);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductSellExists(productSell.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AmountSignId"]     = new SelectList(_context.AmountSign, "AmountSignId", "AmountSignName", productSell.AmountSignId);
            ViewData["NumberSignId"]     = new SelectList(_context.NumberSign, "NumberSignId", "NumberSignName", productSell.NumberSignId);
            ViewData["PaymentMethodId"]  = new SelectList(_context.PaymentMethod, "PaymentMethodId", "PaymentMethodName", productSell.PaymentMethodId);
            ViewData["ProductQualityId"] = new SelectList(_context.ProductQuality, "ProductQualityId", "ProductQualityName", productSell.ProductQualityId);
            ViewData["ProductTypeId"]    = new SelectList(_context.Set <ProductType>(), "ProductTypeId", "ProductTypeName", productSell.ProductTypeId);
            return(View(productSell));
        }
 public ProductSell Add(ProductSell entity)
 {
     return(_context.ProductSell.Add(entity).Entity);
 }
 public void Remove(ProductSell entity)
 {
     throw new System.NotImplementedException();
 }
 public override void remove(ProductSell productSell)
 {
     this._shoppingCart.remove(productSell);
 }
 public override void add(ProductSell productSell)
 {
     this._shoppingCart.add(productSell);
 }
 public async Task AddProductAsync(ProductSell productSell)
 {
     await _context.Set <ProductSell> ().AddAsync(productSell);
 }
Exemple #25
0
 public void AddProductSell(ProductSell productSell)
 {
     //each combination in product sell has to be asserted that it contains all changeable attributes
     ProductSells.Add(productSell);
 }