protected CityViewModel(Address address, IDevAVDbUnitOfWork unitOfWork) { Address = address; Location = new GeoPoint(address.Latitude, address.Longitude); state = new Lazy <DevAV.State>(() => unitOfWork.States.First(s => s.ShortName == address.State)); crest = new Lazy <DevAV.Crest>(() => unitOfWork.Crests.First(c => c.CityName == address.City)); }
public static IEnumerable <Item> GetSalesReport(this IDevAVDbUnitOfWork UnitOfWork) { var orders = UnitOfWork.Orders; var ordersStartDate = orders.Min(x => x.OrderDate); var orderItems = from oi in UnitOfWork.OrderItems join o in orders on oi.OrderId equals o.Id select new { Customer = o.Customer, Total = oi.Total, FY = ((o.OrderDate.Year - ordersStartDate.Year) * 12 + (o.OrderDate.Month - ordersStartDate.Month)) / 12 }; return (from oi in orderItems group oi by new { oi.Customer, oi.FY } into g select new Item { CustomerName = g.Key.Customer.Name, Year = ordersStartDate.Year + (int)g.Key.FY, Month = ordersStartDate.Month, Total = g.Select(o => (decimal?)o.Total).Sum() ?? 0 }); }
public static IEnumerable <Item> GetSalesReport(this IDevAVDbUnitOfWork UnitOfWork) { var orders = UnitOfWork.Orders; var orderItems = from oi in UnitOfWork.OrderItems join o in orders on oi.OrderId equals o.Id where (o.OrderDate >= AnalysisPeriod.Start && o.OrderDate <= AnalysisPeriod.End) select new { Customer = o.Customer, Total = oi.Total, FY = ((o.OrderDate.Year - AnalysisPeriod.Start.Year) * 12 + (o.OrderDate.Month - AnalysisPeriod.Start.Month)) / 12 }; return (from oi in orderItems group oi by new { oi.Customer, oi.FY } into g select new Item { CustomerName = g.Key.Customer.Name, Year = AnalysisPeriod.Start.Year + g.Key.FY, Month = AnalysisPeriod.Start.Month, Total = g.Select(o => (decimal?)o.Total).Sum() ?? 0 }); }
protected override void OnEntityDeleted(long primaryKey, Order entity) { base.OnEntityDeleted(primaryKey, entity); if (orderItemsUnitOfWork != null) { orderItemsUnitOfWork.SaveChanges(); } orderItemsUnitOfWork = null; }
string GetNewInvoiceNumber(IDevAVDbUnitOfWork unitOfWork) { var numberStrings = unitOfWork.Orders.Select(x => x.InvoiceNumber).ToList(); var invoiceNumbers = numberStrings.ConvertAll(x => { int number; return(int.TryParse(x, out number) ? number : 0); }); return((invoiceNumbers.Max() + 1).ToString()); }
protected override void OnBeforeEntityDeleted(long primaryKey, Order entity) { base.OnBeforeEntityDeleted(primaryKey, entity); if (!entity.OrderItems.Any()) { return; } var deletedItemKeys = entity.OrderItems.Select(x => x.Id).ToList(); orderItemsUnitOfWork = this.UnitOfWorkFactory.CreateUnitOfWork(); deletedItemKeys.ForEach(x => { var item = orderItemsUnitOfWork.OrderItems.Find(x); orderItemsUnitOfWork.OrderItems.Remove(item); }); }
public static IEnumerable <Item> GetSalesData(this IDevAVDbUnitOfWork UnitOfWork) { var orders = UnitOfWork.Orders; var orderItems = from oi in UnitOfWork.OrderItems join o in orders on oi.OrderId equals o.Id select new { State = o.Store.Address.State, Date = o.OrderDate, Total = oi.Total }; return (from oi in orderItems group oi by new { oi.State, oi.Date.Year, oi.Date.Month } into g select new Item { State = g.Key.State, Year = g.Key.Year, Month = g.Key.Month, Total = g.Select(o => (decimal?)o.Total).Sum() ?? 0 }); }
public static IEnumerable <Item> GetFinancialData(this IDevAVDbUnitOfWork UnitOfWork) { var orders = UnitOfWork.Orders; var ordersStartDate = orders.Min(x => x.OrderDate); var orderItems = from oi in UnitOfWork.OrderItems join o in orders on oi.OrderId equals o.Id select new { Product = oi.Product, Date = o.OrderDate, Total = oi.Total }; return (from oi in orderItems group oi by new { oi.Product.Category, oi.Date.Year, oi.Date.Month } into g select new Item { ProductCategory = g.Key.Category, Year = g.Key.Year, Month = g.Key.Month, Total = g.Select(x => (decimal?)x.Total).Sum() ?? 0 }); }
public static IEnumerable <Item> GetFinancialData(this IDevAVDbUnitOfWork UnitOfWork) { var orders = UnitOfWork.Orders; var orderItems = from oi in UnitOfWork.OrderItems join o in orders on oi.OrderId equals o.Id where (o.OrderDate >= AnalysisPeriod.Start && o.OrderDate <= AnalysisPeriod.End) select new { Product = oi.Product, Date = o.OrderDate, Total = oi.Total }; return (from oi in orderItems group oi by new { oi.Product.Category, oi.Date.Year, oi.Date.Month } into g select new Item { ProductCategory = g.Key.Category, Year = g.Key.Year, Month = g.Key.Month, Total = g.Select(o => (decimal?)o.Total).Sum() ?? 0 }); }
protected override void OnEntitiesLoaded(IDevAVDbUnitOfWork unitOfWork, IEnumerable <ProductInfoWithSales> entities) { base.OnEntitiesLoaded(unitOfWork, entities); QueriesHelper.UpdateMonthlySales(unitOfWork.OrderItems, entities); }
public ProductAnalysisViewModel() { unitOfWork = DbUnitOfWorkFactory.Instance.CreateUnitOfWork(); }
public CustomerAnalysisViewModel() { unitOfWork = DbUnitOfWorkFactory.Instance.CreateUnitOfWork(); }
protected ProductAnalysisViewModel() { unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork(); }
void ParseDataSource() { unitOfWork = SpreadsheetDataSource.Item1; order = SpreadsheetDataSource.Item2; }
public OrderMailMergeViewModel() { unitOfWork = DbUnitOfWorkFactory.Instance.CreateUnitOfWork(); }
public static CityViewModel Create(Address address, IDevAVDbUnitOfWork unitOfWork) { return(ViewModelSource.Create(() => new CityViewModel(address, unitOfWork))); }
protected StatisticsViewModelBase() { unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork(); FilterType = Period.Lifetime; }
protected override IEnumerable <SalesViewModel> GetActualStatistics(IDevAVDbUnitOfWork unitOfWork) { return(QueriesHelper.GetSaleMapItemsByCity(unitOfWork.OrderItems, EntityId, SelectedAddress.Address.City, FilterType).GroupBy(mi => mi.Customer).Select(gr => new SalesViewModel(gr.Key.Name, gr.CustomSum(mi => mi.Total)))); }
protected override void OnEntitiesLoaded(IDevAVDbUnitOfWork unitOfWork, IEnumerable <CustomerInfo> entities) { base.OnEntitiesLoaded(unitOfWork, entities); QueriesHelper.UpdateCustomerInfoStores(entities, unitOfWork.Customers); }
static DateTime LastOrderDate(IDevAVDbUnitOfWork unitOfWork) { return(unitOfWork.OrderItems.Where(x => x.Order.OrderDate <= DateTime.Today).Max(x => x.Order.OrderDate)); }
protected abstract IEnumerable <SalesViewModel> GetActualStatistics(IDevAVDbUnitOfWork unitOfWork);
protected OrderMailMergeViewModel() { unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork(); }
protected CustomerAnalysisViewModel() { unitOfWork = UnitOfWorkSource.GetUnitOfWorkFactory().CreateUnitOfWork(); }