예제 #1
0
        public async Task RecordChangeHistory(List <PropertyInfo> changes, ChangeType changeType = ChangeType.Change)
        {
            using (var db = new pileEntities())
            {
                var old       = db.Customers.Single(x => x.Id == Id);
                var histories = new List <CustomerHistory>();
                foreach (var change in changes)
                {
                    string oldval = (change.GetValue(old) ?? "<null>").ToString(); // : change.GetValue(old).ToString();
                    string newval = change.GetValue(this) == null ? "<null>" : change.GetValue(this).ToString();

                    var hist = new CustomerHistory
                    {
                        CustomerId = this.Id,
                        Date       = DateTime.Now,
                        EmployeeId = ApplicationUserManager.GetCurrentUserEmployeeId(),
                        Field      = change.Name,
                        Type       = 33,
                        Notes      = string.Format("Old value: {0} - New value: {1}", oldval, newval)
                    };


                    switch (changeType)
                    {
                    case ChangeType.Change:
                        hist.Type = change.GetValue(this) as string == "A" ? 32 : 31;
                        break;

                    case ChangeType.New:
                        hist.Type = 30;
                        break;
                    }

                    histories.Add(hist);
                }

                if (histories.Count() > 0)
                {
                    db.CustomerHistories.AddRange(histories);
                }

                await db.SaveChangesAsync();
            }
        }
예제 #2
0
        private async static Task DeleteRoutes(Customer cust, DateTime afterDate, DateTime?throughDate = null)
        {
            using (var db = new pileEntities())
            {
                if (throughDate == null || !throughDate.HasValue)
                {
                    throughDate = DateTime.MaxValue;
                }

                var routes = db.Routes.Where(
                    x => x.CustomerID == cust.Id &&
                    x.Date >= DateTime.Today &&
                    x.Date >= afterDate &&
                    x.Date < throughDate);

                db.Routes.RemoveRange(routes);
                await db.SaveChangesAsync();
            }
        }