public OpreationResult Create(ProcurementViewModel input)
        {
            var result = new OpreationResult();

            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.UintPrice
                };
                repository.Create(entity);
                context.SaveChanges();
                result.IsSuccessful = true;
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.exception    = ex;
            }
            return(result);
        }
        public OpreationResult Create(SellingViewModel input)
        {
            var result = new OpreationResult();

            try
            {
                BizModel context = new BizModel();
                using (var transaction = context.Database.BeginTransaction())
                {
                    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);
        }
 public static string WriteLog(this OpreationResult value)
 {
     if (value.exception != null)
     {
         string path = DateTime.Now.ToString("yyyy-MM-dd_HH_mm_ss");
         path = path + ".txt";
         File.WriteAllText(path, value.exception.ToString());
         return(path);
     }
     else
     {
         return("沒有存檔");
     }
 }
Esempio n. 4
0
        public OpreationResult Create(SalesManViewModel input)
        {
            var result = new OpreationResult();

            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);
        }
        //public static List<ProductViewModel> FakeProdUcts
        //     = new List<ProductViewModel>();
        public OpreationResult Create(ProductViewModel input)
        {
            var result = new OpreationResult();

            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;
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.exception    = ex;
            }
            return(result);
        }