Exemplo n.º 1
0
        public OperationResult Create(ProcurementViewModel input)
        {
            var result = new OperationResult();

            try
            {
                BizModel    context    = new BizModel();
                var         repository = new BizRepository <Procurement>(context);
                Procurement entity     = new Procurement()
                {
                    PartNo           = input.PartNo,
                    PurchasingDay    = input.PurchasingDay,
                    Quantity         = input.Quantity,
                    InvetoryQuantity = input.InvetoryQuantity,
                    UintPrice        = input.UnitPrice
                };
                repository.Create(entity);
                context.SaveChanges();
                result.IsSuccessful = true;
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.exception    = ex;
            }
            return(result);
        }
Exemplo n.º 2
0
        public OperationResult Create(SellingViewModel input)
        {
            var result = new OperationResult();

            try
            {
                BizModel context = new BizModel();
                using (var transaction = context.Database.BeginTransaction())//Rollback
                {
                    var     sellCount         = input.Quantity;
                    var     procurementRepo   = new BizRepository <Procurement>(context);
                    var     sellingSourceRepo = new BizRepository <SellingSource>(context);
                    var     sellingRepo       = new BizRepository <Selling>(context);
                    Selling entity            = new Selling()
                    {
                        PartNo         = input.PartNo,
                        Quantity       = input.Quantity,
                        SalesJobNumber = input.SalesJobNumber,
                        SellingDay     = input.SellingDay,
                        UnitPrice      = input.UnitPrice
                    };
                    sellingRepo.Create(entity);
                    context.SaveChanges();
                    var products = procurementRepo.GetAll()
                                   .Where((x) => x.PartNo == input.PartNo).OrderBy((x) => x.PurchasingDay);
                    foreach (var p in products)
                    {
                        if (sellCount <= 0)
                        {
                            break;
                        }
                        else
                        {
                            if (p.InvetoryQuantity >= sellCount)
                            {
                                p.InvetoryQuantity = p.InvetoryQuantity - sellCount;
                                CreateSellingSource(sellingSourceRepo, entity.SellingId, p.ProcurementId, sellCount);
                                sellCount = 0;
                            }
                            else
                            {
                                sellCount = sellCount - p.InvetoryQuantity;
                                CreateSellingSource(sellingSourceRepo, entity.SellingId, p.ProcurementId, p.InvetoryQuantity);
                                p.InvetoryQuantity = 0;
                            }
                        }
                    }

                    context.SaveChanges();
                    result.IsSuccessful = true;
                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.exception    = ex;
            }
            return(result);
        }
Exemplo n.º 3
0
        public OperationResult Create(ProductViewModel input)
        {
            var result = new OperationResult();

            try
            {
                BizModel context = new BizModel();
                // context 橋梁 "承上啟下" 資料庫的上下文
                BizRepository <Product> repository
                    = new BizRepository <Product>(context);
                // viewModel 轉成 Model 再給資料庫
                Product entity = new Product()
                {
                    PartNo = input.PartNo, PartName = input.PartName
                };
                repository.Create(entity);
                context.SaveChanges();
                result.IsSuccessful = true;
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.exception    = ex;
            }
            return(result);
        }
Exemplo n.º 4
0
        public OperationResult Create(ProductViewModel input)
        {
            var result = new OperationResult();

            try
            {
                BizModel context = new BizModel();
                BizRepository <Product> repository
                    = new BizRepository <Product>(context);
                Product entity = new Product()
                {
                    PartNo = input.PartNo, PartName = input.PartName
                };
                repository.Create(entity);
                context.SaveChanges();
                result.IsSuccessful = true;

                /*if (FakeProducts.Any((x) => x.PartNo == product.PartNo))
                 * {
                 *  throw new ArgumentException($"PartNo {product.PartNo} exsists");
                 * }
                 * else
                 * {
                 *  FakeProducts.Add(product);
                 *  result.IsSuccessful = true;
                 * }*/
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.exception    = ex;
            }
            return(result);
        }
Exemplo n.º 5
0
        public void Create(Product entity)
        {
            BizModel context = new BizModel();
            BizRepository <Product> repository = new BizRepository <Product>(context);

            repository.Create(entity);
            context.SaveChanges();
        }
Exemplo n.º 6
0
        private void CreateSellingSource(BizRepository <SellingSource> sellingSourceRepo, int sellingId, int procurementId, int sellCount)
        {
            SellingSource sellingSource = new SellingSource()
            {
                ProcurementId = procurementId,
                SellingId     = sellingId,
                Quantity      = sellCount
            };

            sellingSourceRepo.Create(sellingSource);
        }
Exemplo n.º 7
0
        public OperationResult Create(SalesManViewModel input)
        {
            var result = new OperationResult();

            try
            {
                BizModel context = new BizModel();
                BizRepository <SalesMan> repository = new BizRepository <SalesMan>(context);
                SalesMan entity = new SalesMan()
                {
                    Name = input.Name
                };
                repository.Create(entity);
                context.SaveChanges();
                result.IsSuccessful = true;
            }
            catch (Exception ex) {
                result.IsSuccessful = false;
                result.exception    = ex;
            }
            return(result);
        }
Exemplo n.º 8
0
        //假的行為,到目前為止還不知道資料庫的真實內容,測試用
        //public static List<ProductViewModel> FakeProducts = new List<ProductViewModel>();

        public OperationResult Create(ProductViewModel input)
        {
            var result = new OperationResult();

            try
            {
                //if (FakeProducts.Any((x) => x.ParNo == product.PartNo) != null)
                //{
                //    throw new ArgumentException($"PartNo {product.PartNo} is not exsist");
                //}
                //else
                //{
                //    FakeProduct.Add(product);
                //    result.IsSuccessful = true;
                //}

                BizModel context = new BizModel();
                BizRepository <Product> repository = new BizRepository <Product>(context);
                //context 橋梁、承上啟下,接通兩個不同的端點(EX:資料庫、程式)
                Product entity = new Product()
                {
                    PartNo   = input.PartNo,
                    PartName = input.PartName
                };
                repository.Create(entity);
                context.SaveChanges();
                result.IsSuccessful = true;
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.exception    = ex;
            }

            return(result);
        }