protected ProductViewModel(Product product) { IDs = new List<int>{product.ID}; SerialNumber = product.SerialNumber; ModelName = product.Model.Name; CategoryName = product.Model.Category.Name; Notes = product.Notes; SellingPrice = product.SellingPrice; DateSellTo = product.DateSellTo; ModelID = product.ModelID; Origin = TranType.Zero; MoneySpentForProduct = 0; var orderedTransactions = product.Transactions.OrderBy(x => x.Date); if (orderedTransactions.FirstOrDefault() != null && orderedTransactions.FirstOrDefault().Operator != null) SalesmanBought = new SalesmanViewModel(orderedTransactions.FirstOrDefault().Operator.Salesman); foreach (var transaction in orderedTransactions) { if (transaction.TypeID != (int)TranType.Bought && transaction.TypeID != (int)TranType.Repaired && transaction.TypeID != (int)TranType.ToPawn && transaction.TypeID != (int)TranType.ToRepair) continue; if (transaction.TypeID != (int)TranType.ToRepair && transaction.Price != null) MoneySpentForProduct += transaction.Price.Value; if (transaction.TypeID != (int)TranType.Repaired) Origin = (TranType)transaction.TypeID; } Status = orderedTransactions.LastOrDefault() == null ? TranType.Zero : (TranType) orderedTransactions.LastOrDefault().TypeID; }
public TransactionViewModel(Transaction transaction) { ID = transaction.ID; Type = (TranType)transaction.TypeID; Price = transaction.Price; Date = transaction.Date; var product = transaction.Product; if (product != null) { ProductID = product.ID; ModelName = product.Model.Name; CategoryName = product.Model.Category.Name; SerialNumber = product.SerialNumber; } if (transaction.Operator != null) { Salesman = new SalesmanViewModel(transaction.Operator.Salesman); } if (transaction.Contragent != null) { ContragentLastName = new ContragentViewModel(transaction.Contragent); } }
public CashTransactionViewModel(Transaction transaction) { ID = transaction.ID; Date = transaction.Date; CashTranType = (TranType) transaction.TypeID; Salesman = new SalesmanViewModel(transaction.Operator.Salesman); if (transaction.Contragent != null) Contragent = new ContragentViewModel(transaction.Contragent); if (transaction.Price != null) Price = transaction.Price.Value; Notes = transaction.Notes; }
public CashTransactionViewModel(Transaction transaction) { ID = transaction.ID; Date = transaction.Date; CashTranType = (TranType)transaction.TypeID; Salesman = new SalesmanViewModel(transaction.Operator.Salesman); if (transaction.Contragent != null) { Contragent = new ContragentViewModel(transaction.Contragent); } if (transaction.Price != null) { Price = transaction.Price.Value; } Notes = transaction.Notes; }
public SoldProductViewModel(Product product) : base(product) { var ordered = product.Transactions.OrderBy(x => x.Date); var transactionSold = ordered.LastOrDefault(x => x.TypeID == (int)TranType.Sold); if (transactionSold != null) { if (transactionSold.Price != null) PriceSold = transactionSold.Price.Value; SalesmanSold = new SalesmanViewModel(transactionSold.Operator.Salesman); DateSold = transactionSold.Date; } SalesmanWithProfit = Origin == TranType.Bought ? SalesmanSold : SalesmanBought; Profit = PriceSold - MoneySpentForProduct; SalesmanProfit = Profit*((decimal) SalesmanWithProfit.ProfitPercentage/(decimal) 100); }
protected ProductViewModel(Product product) { IDs = new List <int> { product.ID }; SerialNumber = product.SerialNumber; ModelName = product.Model.Name; CategoryName = product.Model.Category.Name; Notes = product.Notes; SellingPrice = product.SellingPrice; DateSellTo = product.DateSellTo; ModelID = product.ModelID; Origin = TranType.Zero; MoneySpentForProduct = 0; var orderedTransactions = product.Transactions.OrderBy(x => x.Date); if (orderedTransactions.FirstOrDefault() != null && orderedTransactions.FirstOrDefault().Operator != null) { SalesmanBought = new SalesmanViewModel(orderedTransactions.FirstOrDefault().Operator.Salesman); } foreach (var transaction in orderedTransactions) { if (transaction.TypeID != (int)TranType.Bought && transaction.TypeID != (int)TranType.Repaired && transaction.TypeID != (int)TranType.ToPawn && transaction.TypeID != (int)TranType.ToRepair) { continue; } if (transaction.TypeID != (int)TranType.ToRepair && transaction.Price != null) { MoneySpentForProduct += transaction.Price.Value; } if (transaction.TypeID != (int)TranType.Repaired) { Origin = (TranType)transaction.TypeID; } } Status = orderedTransactions.LastOrDefault() == null ? TranType.Zero : (TranType)orderedTransactions.LastOrDefault().TypeID; }
public TransactionViewModel(Transaction transaction) { ID = transaction.ID; Type = (TranType)transaction.TypeID; Price = transaction.Price; Date = transaction.Date; var product = transaction.Product; if (product != null) { ProductID = product.ID; ModelName = product.Model.Name; CategoryName = product.Model.Category.Name; SerialNumber = product.SerialNumber; } if (transaction.Operator != null) Salesman = new SalesmanViewModel(transaction.Operator.Salesman); if (transaction.Contragent != null) ContragentLastName = new ContragentViewModel(transaction.Contragent); }
public SoldProductViewModel(Product product) : base(product) { var ordered = product.Transactions.OrderBy(x => x.Date); var transactionSold = ordered.LastOrDefault(x => x.TypeID == (int)TranType.Sold); if (transactionSold != null) { if (transactionSold.Price != null) { PriceSold = transactionSold.Price.Value; } SalesmanSold = new SalesmanViewModel(transactionSold.Operator.Salesman); DateSold = transactionSold.Date; } SalesmanWithProfit = Origin == TranType.Bought ? SalesmanSold : SalesmanBought; Profit = PriceSold - MoneySpentForProduct; SalesmanProfit = Profit * ((decimal)SalesmanWithProfit.ProfitPercentage / (decimal)100); }