public void SetNextPurchaseDate(Bageller nextBageller) { var lastBageller = GetLastBageller(); nextBageller.NextPurchaseDate = lastBageller.NextPurchaseDate.AddDays(7); return; }
public Bageller Save(Bageller item) { var resetDates = false; using (var session = _documentStore.OpenSession()) { if (item.BagellerId == 0) { //set the Id field var queryable = (from bageller in session.Query<Bageller>() orderby bageller.Id descending select bageller.Id).ToList(); var orderedQueryable = queryable.Select(x => x.Replace("bagellers/", "").ToSafeInt()).OrderByDescending(x => x); var lastId = orderedQueryable.Take(1).First(); item.BagellerId = lastId + 1; item.NextPurchaseDate = DateTime.Now.AddMinutes(1); resetDates = true; session.Store(item); session.SaveChanges(); } else { var sessionItem = session.Load<Bageller>(item.Id); sessionItem.InjectFrom(item); //Doing an injection of values because if we just overwrite it, we lose the connection to the session session.SaveChanges(); } } if (resetDates) item.NextPurchaseDate = ResetNextPurchaseDates(); return item; }