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); }
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); }
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); }
public SellingListQueryViewModel GetSellingBySalesMan(int JobNumber) { var result = new SellingListQueryViewModel(); result.Item = new List <SellingQueryViewModel>(); BizModel context = new BizModel(); BizRepository <Selling> SellingRepo = new BizRepository <Selling>(context); BizRepository <SalesMan> SalesManRepo = new BizRepository <SalesMan>(context); var temp = from p in SellingRepo.GetAll() join s in SalesManRepo.GetAll() on p.SalesJobNumber equals s.JobNumber where s.JobNumber == JobNumber select new SellingQueryViewModel { PartNo = p.PartNo, Quantity = p.Quantity, UnitPrice = p.UnitPrice, SalesJobNumber = s.JobNumber, SalesName = s.Name, SellingDay = p.SellingDay, SellingId = p.SellingId, TotalPrice = p.UnitPrice * p.Quantity }; result.Item = temp.ToList(); return(result); }
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); }
public ProcurementListQueryViewModel GetStockList() { var result = new ProcurementListQueryViewModel(); BizModel context = new BizModel(); var procurementRepo = new BizRepository <Procurement>(context); var productRepo = new BizRepository <Product>(context); var temp = from p in productRepo.GetAll() join q in procurementRepo.GetAll() on p.PartNo equals q.PartNo select new { PartNo = p.PartNo, PartName = p.PartName, Quantity = q.InvetoryQuantity }; var group = from t in temp group t by new { t.PartNo, t.PartName } into g select new ProcurementQueryViewModel { PartName = g.Key.PartName, PartNo = g.Key.PartNo, TotalInvetoryQuantity = g.Sum((x) => x.Quantity) }; result.Items = group.ToList(); return(result); }
public bool IsNameExist(SalesManViewModel input) { BizModel context = new BizModel(); BizRepository <SalesMan> repository = new BizRepository <SalesMan>(context); return(repository.GetAll().Any((x) => x.Name == input.Name)); }
public SellingListQueryViewModel GetSellingBySalesAndDay(int jobNumber, DateTime begin, DateTime end) { var result = new SellingListQueryViewModel(); BizModel context = new BizModel(); var sellingRepo = new BizRepository <Selling>(context); var salesManRepo = new BizRepository <SalesMan>(context); var temp = from selling in sellingRepo.GetAll() join sales in salesManRepo.GetAll() on selling.SalesJobNumber equals sales.JobNumber where selling.SalesJobNumber == jobNumber && selling.SellingDay >= begin && selling.SellingDay < end select new SellingQueryViewModel { PartNo = selling.PartNo, Quantity = selling.Quantity, SalesJobNumber = selling.SalesJobNumber, SalesName = sales.Name, SellingDay = selling.SellingDay, SellingId = selling.SellingId, UnitPrice = selling.UnitPrice, TotalPrice = selling.UnitPrice * selling.Quantity }; result.Items = temp.ToList(); return(result); }
public List <Product> GetAll() { BizModel content = new BizModel(); BizRepository <Product> repository = new BizRepository <Product>(content); var result = repository.GetAll().OrderBy((x) => x.PartNo).ToList(); return(result); }
/*protected BizModel Context * { get { return _context; } }*/ public BizRepository(BizModel context) { if (context == null) { throw new ArgumentNullException(); } _context = context; }
public Product GetByPartNo(string partNo) { BizModel context = new BizModel(); BizRepository <Product> repository = new BizRepository <Product>(context); var result = repository.GetAll().FirstOrDefault(x => x.PartNo == partNo); return(result); }
public List <Product> GetAll() { BizModel context = new BizModel(); BizRepository <Product> repository = new BizRepository <Product>(context); var result = repository.GetAll().ToList(); return(result); }
public void Create(Product entity) { BizModel context = new BizModel(); BizRepository <Product> repository = new BizRepository <Product>(context); repository.Create(entity); context.SaveChanges(); }
static void Main(string[] args) { BizModel model = new BizModel(); var allEmployees = model.Employees; foreach (Employee e1 in allEmployees) { Console.WriteLine(e1.Name); } Console.ReadLine(); var triangleEmployees = model.Employees.Where(e2 => e2.Department.Name == "Aspit Trekanten").ToList(); foreach (Employee e2 in triangleEmployees) { Console.WriteLine(e2.Name); } Console.ReadLine(); // INSERT //Department storKbh = model.Departments.SingleOrDefault(d => d.Name == "Aspit Storkøbenhavn"); //Employee employee = new Employee() { Name = "STLA", Department = storKbh }; //model.Employees.Add(employee); //model.SaveChanges(); foreach (Employee e in model.Employees) { Console.WriteLine(e.Name + "\t" + e.Department.Name); } Console.ReadLine(); //Delete var steen = model.Employees.Where(e => e.Name == "STLA").FirstOrDefault(); model.Employees.Remove(steen); model.SaveChanges(); foreach (Employee e in model.Employees) { Console.WriteLine(e.Name + "\t" + e.Department.Name); } Console.ReadLine(); var klement = model.Employees.SingleOrDefault(e => e.Name == "KLJO"); klement.Name = "KLJOOOO"; model.SaveChanges(); foreach (Employee e in model.Employees) { Console.WriteLine(e.Name + "\t" + e.Department.Name); } Console.ReadLine(); }
public bool GetTellerWorkload(string tellerCode, string tellerName, DateTime date, TellerBiz teller) { BizFactor factor = new BizFactor(); // TODO: 获取折算因子 BizModel model = new BizModel(); model.TellerName = tellerName; model.TellerCode = tellerCode; model.WorkDate = date; model.TotalBiz.CorporateAccount = teller.CorporateAccount * factor.CorporateAccountFactor; model.TotalBiz.PersonalAccount = teller.PersonalAccount * factor.PersonalAccountFactor; model.TotalBiz.CorporateClose = teller.CorporateClose * factor.CorporateCloseFactor; model.TotalBiz.PersonalClose = teller.PersonalClose * factor.PersonalCloseFactor; model.TotalBiz.CorporateCash = teller.CorporateCash * factor.CorporateCashFactor; model.TotalBiz.PersonalCash = teller.PersonalCash * factor.PersonalCashFactor; model.TotalBiz.OtherDepositCash = teller.OtherDepositCash * factor.OtherDepositFactor; model.TotalBiz.CorporateSettle = teller.CorporateSettle * factor.CorporateSettleFactor; model.TotalBiz.PersonalSettle = teller.PersonalSettle * factor.PersonalSettleFactor; model.TotalBiz.VostroPrint = teller.VostroPrint * factor.VostroPrintFactor; model.TotalBiz.Inquiry = teller.Inquiry * factor.InquiryFactor; model.TotalBiz.OtherSettle = teller.OtherSettle * factor.OtherSettleFactor; model.TotalBiz.CorporateSMS = teller.CorporateSMS * factor.CorporateSMSFactor; model.TotalBiz.PersonalSMS = teller.PersonalSMS * factor.PersonalSMSFactor; model.TotalBiz.CorporateBanking = teller.CorporateBanking * factor.CorporateBankingFactor; model.TotalBiz.PersonalBanking = teller.PersonalBanking * factor.PersonalBankingFactor; model.TotalBiz.MobileBanking = teller.MobileBanking * factor.MobileBankingFactor; model.TotalBiz.LoanCollection = teller.LoanCollection * factor.LoanCollectionFactor; model.TotalBiz.ManualInterset = teller.ManualInterset * factor.ManualInterestFactor; model.TotalBiz.DraftSign = teller.DraftSign * factor.DraftSignFactor; model.TotalBiz.Remittance = teller.Remittance * factor.RemittanceFactor; model.TotalBiz.TicketDiscount = teller.TicketDiscount * factor.DiscountTicketFactor; model.TotalBiz.ElectroTicketDiscount = teller.ElectroTicketDiscount * factor.ElectroTicketFactor; model.TotalBiz.EastChinaDraft = teller.EastChinaDraft * factor.EastChinaTicketFactor; model.TotalBiz.SellBlankTicket = teller.SellBlankTicket * factor.SellBlankTicketFactor; model.TotalBiz.LossLiftLoss = teller.LossLiftLoss * factor.LossLiftLossFactor; model.TotalBiz.InquiryFrozen = teller.InquiryFrozen * factor.InquiryFrozenFactor; model.TotalBiz.CtrlRelease = teller.CtrlRelease * factor.CtrlReleaseFactor; model.TotalBiz.RedBlue = teller.RedBlue * factor.RedBlueFactor; model.TotalBiz.BatchModuleMaintain = teller.BatchModuleMaintain * factor.BatchModuleFactor; model.TotalBiz.BatchUpload = teller.BatchUpload * factor.BatchUploadFactor; model.TotalBiz.BatchDownload = teller.BatchDownload * factor.BatchDownloadFactor; model.TotalBiz.BatchAccount = teller.BatchAccount * factor.BatchAccountFactor; model.TotalBiz.CardApply = teller.CardApply * factor.CardApplyFactor; model.TotalBiz.CardLoss = teller.CardLoss * factor.CardLoassFactor; model.TotalBiz.CardActivate = teller.CardActivate * factor.CardActivateFactor; model.TotalBiz.OtherService = teller.OtherService * factor.OtherServiceFactor; model.TotalBiz.CashTransferAmount = teller.CashTransferAmount * factor.CashTransferAmountFactor; model.TotalBiz.OtherCashAmount = teller.OtherCashAmount * factor.OtherCashAmountFactor; // TODO: 存入数据库 return(true); }
public int GetStock(string partNo) { BizModel context = new BizModel(); var repository = new BizRepository <Procurement>(context); var items = repository.GetAll().Where((x) => x.PartNo == partNo); int result = 0; if (items.Count() > 0) { result = items.Sum((x) => x.InvetoryQuantity); } return(result); }
public int GetStocks(string PartNo) { BizModel context = new BizModel(); BizRepository <Procurement> repository = new BizRepository <Procurement>(context); var item = repository.GetAll().Where(x => x.PartNo == PartNo); var result = 0; if (item.Count() > 0) { result = item.Sum(x => x.InvetoryQuantity); } return(result); }
public ProductListViewModel GetProducts() { var result = new ProductListViewModel(); result.Items = new List<ProductViewModel>(); BizModel context = new BizModel(); BizRepository<Product> repository = new BizRepository<Product>(context); foreach (var item in repository.GetAll().OrderBy((x) => x.PartNo)) { var p = new ProductViewModel() { PartNo = item.PartNo, PartName = item.PartName }; result.Items.Add(p); } return result; }
public SalesManListViewModel GetSalesMen() { var result = new SalesManListViewModel(); result.Items = new List <SalesManViewModel>(); BizModel context = new BizModel(); var repository = new BizRepository <SalesMan>(context); foreach (var item in repository.GetAll().OrderBy((x) => x.JobNumber)) { var p = new SalesManViewModel() { JobNumber = item.JobNumber, Name = item.Name }; result.Items.Add(p); } return(result); }
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); }
//假的行為,到目前為止還不知道資料庫的真實內容,測試用 //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); }
public List <Employee> GetAll() { BizModel model = new BizModel(); return(model.Employees.ToList()); }