Пример #1
0
        public async Task <ActionResult <ArticleSale> > PostArticleSaleData(ArticleSale articleSaleData)
        {
            _context.ArticleSaleData.Add(articleSaleData);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetArticleSaleData", new { id = articleSaleData.Id }, articleSaleData));
        }
Пример #2
0
        public void SellArticle(SupplierArticle article, int buyerId)
        {
            if (article == null)
            {
                throw new Exception("Could not order article");
            }

            _logger.Debug("Trying to sell article with id=" + article.Id);

            ArticleSale sale = new ArticleSale()
            {
                ArticleId = article.Id,
                BuyerId   = buyerId,
                Date      = DateTime.Now
            };

            try
            {
                _articleRepository.AddArticleSale(sale);
                _logger.Info("Article with id=" + article.Id + " is sold.");
            }
            catch (ArgumentNullException ex)
            {
                _logger.Error("Could not save article with id=" + article.Id);
                throw new Exception("Could not save article with id");
            }
            catch (Exception)
            {
            }
        }
Пример #3
0
        public ArticleSale AddArticleSale(ArticleSale articleSale)
        {
            try
            {
                connection.Open();

                var artileSalePrice = ArticlePrices.FirstOrDefault(item => item.Id == articleSale.ArticlePriceId);
                if (artileSalePrice == null)
                {
                    throw new Exception($"Не найдена цена для покупки с ИД = {articleSale.ArticlePriceId}");
                }

                decimal total = (decimal)articleSale.Quantity * artileSalePrice.Value;

                //
                var command = GetDbCommandByQuery(
                    $"insert into WAREHOUSE_SALES (ENTRY_DATE, SALE_DIRECTION, TOTAL) " +
                    $"values ('{articleSale.CreateDate.ToString("yyyy-MM-dd")}', '1', {total}) " +
                    $"returning ID");

                int warehouseSalesId = (int)command.ExecuteScalar();
                command.Transaction.Commit();
                command.Dispose();

                //
                command = GetDbCommandByQuery($"select NUMBER from WAREHOUSE_SALES where ID = {warehouseSalesId}");
                var reader = command.ExecuteReader();
                reader.Read();
                string warehouseSalesNumber = reader.GetFieldFromReader <string>("NUMBER");
                command.Transaction.Commit();
                command.Dispose();

                //
                command = GetDbCommandByQuery($"update WAREHOUSE_SALES set NUMBER = '{GetArticleSaleNumber(warehouseSalesNumber)}' where ID = {warehouseSalesId};");
                command.ExecuteNonQuery();
                command.Transaction.Commit();
                command.Dispose();

                //
                command = GetDbCommandByQuery(
                    $"insert into WAREHOUSE_SALES_DETAIL (WAREHOUSE_SALES_ID, WAREHOUSE_ID, QUANTITY, PRICE_VALUE, TOTAL, SERIAL_NUMBER) " +
                    $"values ({warehouseSalesId}, {artileSalePrice.Article.Id}, {articleSale.Quantity}, {artileSalePrice.Value}, {total}, NULL);");

                command.ExecuteNonQuery();
                command.Transaction.Commit();
                command.Dispose();

                return(articleSale);
            }
            catch (Exception ex)
            {
                throw new SystemException("Ошибка добавления покупки товара", ex);
            }
            finally
            {
                connection?.Close();
            }
        }
        public ArticleSale AddArticleSale(ArticleSale sale)
        {
            if (sale == null)
            {
                throw new ArgumentNullException(nameof(sale));
            }

            _logger.Debug($" >> Saving article sale with article id: {sale.ArticleId} and buyerId: {sale.BuyerId}");

            _articaleSales.Add(sale);

            _logger.Debug($" << saved article sale with article id: {sale.ArticleId} and buyerId: {sale.BuyerId}");

            return(sale);
        }
Пример #5
0
 public ArticleSale AddArticleSale(ArticleSale articleSale)
 {
     RepositoriesFactory.Get <ArticleSale>().Add(articleSale);
     return(articleSale);
 }