public void DeleteCustomer_WithReservation() { var customer = CreateCustomer("cust", profiles[0]); var activity = CreateActivity("test", profiles[0]); ScheduleEntry entry = new ScheduleEntry(); entry.Activity = activity; entry.Profile = profiles[0]; entry.MyPlace = GetDefaultMyPlace(profiles[0]); entry.StartTime = DateTime.Now; entry.EndTime = DateTime.Now.AddHours(1); insertToDatabase(entry); ScheduleEntryReservation reservation = new ScheduleEntryReservation(); reservation.Customer = customer; reservation.Name = "test"; reservation.DateTime = DateTime.Now; reservation.Profile = profiles[0]; reservation.ScheduleEntry = entry; insertToDatabase(reservation); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); var customerDto = customer.Map <CustomerDTO>(); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.DeleteCustomer(data.Token, customerDto); }); }
void createChampionshipEntryForCustomer(Championship championship, ScheduleEntryReservation reservation) { Exercise benchPress = Session.Load <Exercise>(new Guid("ece5dfd7-f995-45ae-bb34-067f26c4f7b4")); Exercise deadlift = Session.Load <Exercise>(new Guid("505988e1-5663-41f1-aa1a-9b92ea584263")); Exercise squad = Session.Load <Exercise>(new Guid("3e06a130-b811-4e45-9285-f087403615bf")); var championshipCustomer = new ChampionshipCustomer(); championshipCustomer.Customer = reservation.Customer; championship.Customers.Add(championshipCustomer); ChampionshipEntry entryChamp = new ChampionshipEntry(); entryChamp.Customer = championshipCustomer; entryChamp.Exercise = benchPress; championship.Entries.Add(entryChamp); if (championship.ChampionshipType == ChampionshipType.Trojboj) { entryChamp = new ChampionshipEntry(); entryChamp.Customer = championshipCustomer; entryChamp.Exercise = deadlift; championship.Entries.Add(entryChamp); entryChamp = new ChampionshipEntry(); entryChamp.Customer = championshipCustomer; entryChamp.Exercise = squad; championship.Entries.Add(entryChamp); } }
Payment calculatePayement(ScheduleEntryReservation reservation, bool forLeave) { Payment zakup = null; if (reservation.Payment == null) { reservation.Price = reservation.ScheduleEntry.Price; if (reservation.Price > 0) { zakup = new Payment(); zakup.Product = reservation; zakup.DateTime = Configuration.TimerService.UtcNow; zakup.Count = 1; } } //if (forLeave) //{ // //sprawdz czy zaplacono karnetem gdzie byla informacja o dopłacie za przekroczenie czasu. Jesli trzeba to nalezy tez odliczyc czas pobytu z pozostałęgo czasu na karnecie // NHibernateUtil.Initialize(reservation.Payement); // var wejscieKarnet = reservation.Payement.GetRealObject<ZakupBase>() as WejscieNaKarnet; // var time = reservation.LeaveDateTime.Value - reservation.EnterDateTime.Value; // TaryfaPrice taryfaPrice = getCurrentTaryfaPrice(reservation, wejscieKarnet); // if (wejscieKarnet != null && wejscieKarnet.Karnet.PozostalyCzas != null) // {//karnet przechowuje pozostały czas do wykorzystania dlatego trzeba zakutalizować tą liczbę // wejscieKarnet.Karnet.PozostalyCzas -= time; // if (wejscieKarnet.Karnet.PozostalyCzas <= TimeSpan.Zero) // { // wejscieKarnet.Karnet.State = KarnetState.Expired; // } // if (wejscieKarnet.Karnet.PozostalyCzas.Value.TotalMinutes < 0) // {//musimy obliczyc doplate bo przekroczono czas pobytu a na karnecie tyle nie ma // decimal? doplata = taryfaPrice.Doplata; // if (doplata == null) // {//doplata nie została ustawiona także nalicz kwotę dopłaty z ceny usługi // //tutaj już nie podajemy karnetu żeby cena została pobrana od usługi tylko // doplata = calculateDoplataFromUslugaPrice(reservation, wejscieKarnet); // } // zakup = createDoplata(reservation, doplata.Value, wejscieKarnet.Karnet.PozostalyCzas.Value.Duration(), zakup); // //wyzeruj pozostaly czas zeby nastepnym razem nie mozna bylo wejsc na ten karnet // wejscieKarnet.Karnet.PozostalyCzas = TimeSpan.Zero; // } // } // else if (reservation.Usluga.DoplataStartAfter != null) // { // //calculate a price // //TODO:Check. For usluga can have default taryfa price not defined. Is this good? // if (taryfaPrice != null && taryfaPrice.Doplata.HasValue && taryfaPrice.Doplata.Value > 0) // { // var diff = (time - reservation.Usluga.CzasTrwania) - reservation.Usluga.DoplataStartAfter.Value; // zakup = createDoplata(reservation, taryfaPrice.Doplata.Value, diff, zakup); // } // } //} return(zakup); }
protected ScheduleEntryReservation CreateReservation(ScheduleEntryBase entry, Customer customer) { ScheduleEntryReservation reservation = new ScheduleEntryReservation(); reservation.Name = "test"; reservation.ScheduleEntry = entry; reservation.Profile = customer.Profile; entry.Reservations.Add(reservation); reservation.Customer = customer; insertToDatabase(reservation); return(reservation); }
private static void undoReservation(ScheduleEntryReservation dbReservation, ScheduleEntryBase dbEntry) { if (dbReservation == null) { throw new AlreadyOccupiedException("Selected customer isn't on the reservation list"); } if (dbEntry.State != ScheduleEntryState.Planned) { throw new InvalidOperationException("Cannot undo reservation for entries with other statuses than Planned"); } dbReservation.ScheduleEntry = null; dbEntry.Reservations.Remove(dbReservation); //Championship championship = dbEntry as Championship; //if (championship != null) //{ // var championshipCustomer=championship.Customers.Where(x => x.Customer.GlobalId == dbReservation.Customer.GlobalId).SingleOrDefault(); // if (championshipCustomer != null) // { // championship.Customers.Remove(championshipCustomer); // } // championship.Entries. //} }
public override void BuildDatabase() { using (var tx = Session.BeginTransaction()) { profiles.Clear(); activities.Clear(); entries.Clear(); customers.Clear(); koszyki.Clear(); profiles.Add(CreateProfile(Session, "test1")); profiles.Add(CreateProfile(Session, "test2")); var customer = CreateCustomer("cust1", profiles[0]); customers.Add(customer); customer = CreateCustomer("cust2", profiles[0]); customers.Add(customer); customer = CreateCustomer("cust3", profiles[1]); customers.Add(customer); var activity = CreateActivity("Swimming", profiles[0], 10); activities.Add(activity); activity = CreateActivity("Strength training", profiles[0], 15); activities.Add(activity); ScheduleEntry entry = new ScheduleEntry(); entry.Profile = profiles[0]; entry.MyPlace = GetDefaultMyPlace(profiles[0]); entry.StartTime = DateTime.UtcNow.AddDays(-10); entry.EndTime = DateTime.UtcNow.AddDays(-10).AddHours(1); entry.Activity = activities[0]; entry.MaxPersons = 3; entries.Add(entry); ScheduleEntryReservation reservation = new ScheduleEntryReservation(); reservation.Customer = customers[0]; reservation.Name = "test"; reservation.DateTime = DateTime.UtcNow; reservation.Profile = profiles[0]; reservation.Price = activities[0].Price; reservation.ScheduleEntry = entry; entry.Reservations.Add(reservation); insertToDatabase(entry); entry = new ScheduleEntry(); entry.Profile = profiles[0]; entry.Activity = activities[1]; entry.MyPlace = GetDefaultMyPlace(profiles[0]); entry.StartTime = DateTime.UtcNow.AddDays(-10); entry.EndTime = DateTime.UtcNow.AddDays(-10).AddHours(1); entry.MaxPersons = 1; entries.Add(entry); reservation = new ScheduleEntryReservation(); reservation.Customer = customers[0]; reservation.Name = "test"; reservation.DateTime = DateTime.UtcNow; reservation.Profile = profiles[0]; reservation.Price = activities[1].Price; reservation.ScheduleEntry = entry; entry.Reservations.Add(reservation); insertToDatabase(entry); entry = new ScheduleEntry(); entry.Profile = profiles[1]; entry.MyPlace = GetDefaultMyPlace(profiles[1]); entry.Activity = activities[1]; entry.StartTime = DateTime.UtcNow.AddDays(-5); entry.EndTime = DateTime.UtcNow.AddDays(-5).AddHours(1); entry.MaxPersons = 1; entry.Activity = activities[1]; entries.Add(entry); reservation = new ScheduleEntryReservation(); reservation.Customer = customers[2]; reservation.Name = "test"; reservation.Profile = profiles[1]; reservation.DateTime = DateTime.UtcNow; reservation.Price = 11; reservation.ScheduleEntry = entry; entry.Reservations.Add(reservation); insertToDatabase(entry); entry = new ScheduleEntry(); entry.Profile = profiles[0]; entry.MyPlace = GetDefaultMyPlace(profiles[0]); entry.Activity = activities[1]; entry.StartTime = DateTime.UtcNow.AddDays(-22); entry.EndTime = DateTime.UtcNow.AddDays(-22).AddHours(1); entry.MaxPersons = 1; entries.Add(entry); reservation = new ScheduleEntryReservation(); reservation.Customer = customers[0]; reservation.Name = "test"; reservation.DateTime = DateTime.UtcNow; reservation.Profile = profiles[0]; reservation.Price = activities[1].Price; reservation.ScheduleEntry = entry; entry.Reservations.Add(reservation); insertToDatabase(entry); var koszyk = new PaymentBasket(); koszyk.DateTime = DateTime.UtcNow.AddDays(-10); koszyk.Profile = profiles[0]; koszyk.Customer = customers[0]; koszyk.TotalPrice = 20; var zakup = new Payment(); zakup.Product = entries[0].Reservations.ElementAt(0); entries[0].Reservations.ElementAt(0).Payment = zakup; zakup.PaymentBasket = koszyk; koszyk.Payments.Add(zakup); insertToDatabase(koszyk); koszyki.Add(koszyk); koszyk = new PaymentBasket(); koszyk.DateTime = DateTime.UtcNow.AddDays(-8); koszyk.Customer = customers[0]; koszyk.Profile = profiles[0]; koszyk.TotalPrice = 11; zakup = new Payment(); zakup.Product = entries[1].Reservations.ElementAt(0); entries[1].Reservations.ElementAt(0).Payment = zakup; zakup.PaymentBasket = koszyk; koszyk.Payments.Add(zakup); insertToDatabase(koszyk); koszyki.Add(koszyk); koszyk = new PaymentBasket(); koszyk.DateTime = DateTime.UtcNow.AddDays(-8); koszyk.Profile = profiles[1]; koszyk.Customer = customers[2]; koszyk.TotalPrice = 11; zakup = new Payment(); zakup.Product = entries[2].Reservations.ElementAt(0); entries[2].Reservations.ElementAt(0).Payment = zakup; zakup.PaymentBasket = koszyk; koszyk.Payments.Add(zakup); insertToDatabase(koszyk); tx.Commit(); } }
private ScheduleEntryReservation makeReservation(Profile dbProfile, ScheduleEntryBase dbEntry, Customer dbCustomer, ScheduleEntryReservation res) { //except anonymous cusomers if (res != null && !dbCustomer.IsVirtual) { throw new AlreadyOccupiedException("Selected customer is already in the reservation list"); } Championship championship = dbEntry as Championship; if (championship != null && dbCustomer.IsVirtual) { throw new InvalidOperationException("Cannot make reservation to championship for virtual customer"); } ScheduleEntryReservation reservation = null; if (dbEntry.State != ScheduleEntryState.Planned) { throw new InvalidOperationException("Cannot make reservations for entries with Done state"); } if (!dbCustomer.IsVirtual) { //check if this customer has reservation for another acitivity at the same time int count = Session.QueryOver <ScheduleEntry>().JoinAlias(x => x.Reservations, () => reservation).Where( x => x.GlobalId != dbEntry.GlobalId && (x.StartTime <= dbEntry.StartTime && x.EndTime > dbEntry.StartTime || x.StartTime < dbEntry.EndTime && x.EndTime >= dbEntry.EndTime) && x.Profile == dbProfile && reservation.Customer == dbCustomer).RowCount(); if (count > 0) { throw new AlreadyOccupiedException("Selected customer is already in the reservation list for another activity"); } } reservation = new ScheduleEntryReservation(); reservation.DateTime = Configuration.TimerService.UtcNow; reservation.Customer = dbCustomer; reservation.Profile = dbProfile; //if (dbEntry != null) //{ reservation.ScheduleEntry = dbEntry; dbEntry.Reservations.Add(reservation); //} //else //{ // reservation.Room = dbRoom; // reservation.Usluga = dbRoom.FreeEnterUsluga; //} ScheduleEntry activityEntry = dbEntry as ScheduleEntry; Championship championEntry = dbEntry as Championship; if (activityEntry != null) { reservation.Name = string.Format("{0}:{1}", activityEntry.Activity.Name, dbEntry.StartTime); } else { //championship entry //TODO:Translate reservation.Name = championEntry.ChampionshipType.ToString(); } //Championship championship = dbEntry as Championship; //if (championship != null) //{ // createChampionshipEntryForCustomer(championship,reservation); //} res = reservation; Session.Save(res); return(res); }
public override void BuildDatabase() { using (var tx = Session.BeginTransaction()) { profiles.Clear(); products.Clear(); customers.Clear(); profiles.Add(CreateProfile(Session, "test1")); profiles.Add(CreateProfile(Session, "test2")); var customer = CreateCustomer("cust1", profiles[0]); customers.Add(customer); customer = CreateCustomer("cust2", profiles[0]); customers.Add(customer); customer = CreateCustomer("cust3", profiles[1]); customers.Add(customer); var activity = CreateActivity("Activity", profiles[0]); ScheduleEntry entry = new ScheduleEntry(); entry.Profile = profiles[0]; entry.MyPlace = GetDefaultMyPlace(profiles[0]); entry.Activity = activity; Session.Save(entry); ScheduleEntryReservation reservation = new ScheduleEntryReservation(); reservation.Profile = profiles[0]; reservation.DateTime = DateTime.UtcNow.Date.AddDays(-1); reservation.Customer = customers[0]; reservation.Name = "test1"; reservation.EnterDateTime = DateTime.UtcNow.AddDays(-1); reservation.LeaveDateTime = DateTime.UtcNow.AddDays(-1); reservation.ScheduleEntry = entry; products.Add(reservation); insertToDatabase(reservation); reservation = new ScheduleEntryReservation(); reservation.Profile = profiles[0]; reservation.DateTime = DateTime.UtcNow.Date.AddDays(-2); reservation.Customer = customers[0]; reservation.Name = "test2"; reservation.EnterDateTime = DateTime.UtcNow.AddDays(-1); reservation.LeaveDateTime = DateTime.UtcNow.AddDays(-1); reservation.ScheduleEntry = entry; insertToDatabase(reservation); products.Add(reservation); reservation.Payment = CreatePayment(reservation, profiles[0]); reservation = new ScheduleEntryReservation(); reservation.Profile = profiles[0]; reservation.DateTime = DateTime.UtcNow.Date.AddDays(-3); reservation.Customer = customers[1]; reservation.Name = "test3"; reservation.EnterDateTime = DateTime.UtcNow.AddDays(-1); reservation.LeaveDateTime = DateTime.UtcNow.AddDays(-1); reservation.ScheduleEntry = entry; products.Add(reservation); insertToDatabase(reservation); reservation = new ScheduleEntryReservation(); reservation.Profile = profiles[1]; reservation.DateTime = DateTime.UtcNow.Date.AddDays(-2); reservation.Customer = customers[1]; reservation.Name = "test4"; reservation.EnterDateTime = DateTime.UtcNow.AddDays(-1); reservation.LeaveDateTime = DateTime.UtcNow.AddDays(-1); reservation.ScheduleEntry = entry; insertToDatabase(reservation); tx.Commit(); } }