Exemple #1
0
        public void Undo_StatusDone()
        {
            var         profile            = (ProfileDTO)profiles[0].Tag;
            SessionData data               = CreateNewSession(profile, ClientInformation);
            ReservationOperationResult res = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                res = Service.ReservationsOperation(data.Token, param);
            });

            entries[0]       = Session.Get <ScheduleEntry>(entries[0].GlobalId);
            entries[0].State = ScheduleEntryState.Done;
            insertToDatabase(entries[0]);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.ReservationId = res.Reservation.GlobalId;
                param.OperationType = ReservationsOperationType.Undo;
                Service.ReservationsOperation(data.Token, param);
            });
        }
Exemple #2
0
        public void Undo_ForVirtualCustomer()
        {
            var         profile            = (ProfileDTO)profiles[0].Tag;
            SessionData data               = CreateNewSession(profile, ClientInformation);
            ReservationOperationResult res = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[3].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                res = Service.ReservationsOperation(data.Token, param);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.ReservationId = res.Reservation.GlobalId;
                param.OperationType = ReservationsOperationType.Undo;
                Service.ReservationsOperation(data.Token, param);
            });


            var db = Session.Get <ScheduleEntry>(entries[0].GlobalId);

            Assert.AreEqual(0, db.Reservations.Count);
        }
Exemple #3
0
        public void MakeReservationThreeForTheSameActivity_VirtualCustomer()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[3].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                Service.ReservationsOperation(data.Token, param);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[3].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                Service.ReservationsOperation(data.Token, param);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[3].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                Service.ReservationsOperation(data.Token, param);
            });
            var count = Session.QueryOver <ScheduleEntryReservation>().RowCount();

            Assert.AreEqual(3, count);
        }
Exemple #4
0
        public void Undo_ForChampionships()
        {
            var         profile      = (ProfileDTO)profiles[0].Tag;
            SessionData data         = CreateNewSession(profile, ClientInformation);
            var         championship = CreateChampionship(profiles[0], "test");

            championship.State = ScheduleEntryState.Planned;
            insertToDatabase(championship);

            ReservationOperationResult res = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = championship.GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                res = Service.ReservationsOperation(data.Token, param);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.ReservationId = res.Reservation.GlobalId;
                param.OperationType = ReservationsOperationType.Undo;
                res = Service.ReservationsOperation(data.Token, param);
            });

            Assert.IsNotNull(res.ScheduleEntry as ScheduleChampionshipDTO);
            var db = Session.Get <Championship>(championship.GlobalId);

            Assert.AreEqual(0, db.Reservations.Count);
        }
Exemple #5
0
        public ReservationOperationResult ReservationsOperation(Token token, ReservationsOperationParam param)
        {
            var securityInfo = SecurityManager.EnsureAuthentication(token);
            var service      = new ReservationService(Session, securityInfo, Configuration);

            return(service.ReservationsOperation(param));
        }
Exemple #6
0
        public void MakeAndPresent_StatePlanned()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);
            ReservationOperationResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                result = Service.ReservationsOperation(data.Token, param);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.ReservationId = result.Reservation.GlobalId;
                param.OperationType = ReservationsOperationType.Presnet;
                result = Service.ReservationsOperation(data.Token, param);
                UnitTestHelper.CompareDateTime(entries[0].StartTime, result.Reservation.EnterDateTime.Value);
                UnitTestHelper.CompareDateTime(entries[0].EndTime, result.Reservation.LeaveDateTime.Value);
            });
            var dbReservation = Session.Get <ScheduleEntryReservation>(result.Reservation.GlobalId);

            UnitTestHelper.CompareDateTime(entries[0].StartTime, dbReservation.EnterDateTime.Value);
            UnitTestHelper.CompareDateTime(entries[0].EndTime, dbReservation.LeaveDateTime.Value);
        }
Exemple #7
0
        public void Make()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                Service.ReservationsOperation(data.Token, param);
            });

            var db = Session.Get <ScheduleEntry>(entries[0].GlobalId);

            Assert.AreEqual(1, db.Reservations.Count);
            Assert.AreEqual(customers[0].GlobalId, db.Reservations.ElementAt(0).Customer.GlobalId);
            Assert.IsNull(db.Reservations.ElementAt(0).LeaveDateTime);
            Assert.IsNull(db.Reservations.ElementAt(0).EnterDateTime);
            Assert.IsNull(db.Reservations.ElementAt(0).Payment);
            Assert.AreEqual(activities[0].Price, db.Reservations.ElementAt(0).Price);
            Assert.AreEqual(profile.GlobalId, db.Reservations.ElementAt(0).Profile.GlobalId);
            Assert.Greater(db.Reservations.ElementAt(0).DateTime, DateTime.MinValue);
        }
 public void CancelReserve(IList <ScheduleEntryReservationDTO> reservations)
 {
     reservationOperation(reservations.Cast <BAGlobalObject>().ToList(), delegate(BAGlobalObject obj)
     {
         ReservationsOperationParam param = new ReservationsOperationParam();
         param.ReservationId = obj.GlobalId;
         param.OperationType = ReservationsOperationType.Undo;
         return(param);
     });
 }
        public void SetStatus(ScheduleEntryState scheduleEntryState)
        {
            var list = new BAGlobalObject[] { SelectedEntry };

            reservationOperation(list.ToList(), delegate(BAGlobalObject obj)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.EntryId       = obj.GlobalId;
                param.OperationType = scheduleEntryState == ScheduleEntryState.Done ? ReservationsOperationType.StatusDone : ReservationsOperationType.StatusCancelled;
                return(param);
            });
        }
        public void GroupReserve(IEnumerable <CustomerGroupDTO> groups)
        {
            var selectedEntry = SelectedEntry;

            reservationOperation(groups.Cast <BAGlobalObject>().ToList(), delegate(BAGlobalObject obj)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = obj.GlobalId;
                param.EntryId       = selectedEntry.GlobalId;
                param.OperationType = ReservationsOperationType.MakeGroup;
                return(param);
            });
        }
Exemple #11
0
        public void UndoReservationWithoutReservation()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Undo;
                Service.ReservationsOperation(data.Token, param);
            });
        }
Exemple #12
0
        public void Payment_MakeReservation()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                var res             = Service.ReservationsOperation(data.Token, param);
                Assert.AreEqual(activities[0].Price, res.Payment.Product.Price);
            });
        }
 public void SetPresent(IList <ScheduleEntryReservationDTO> reservations, bool isPresent)
 {
     reservationOperation(reservations.Cast <BAGlobalObject>().ToList(), delegate(BAGlobalObject obj)
     {
         var reservation = (ScheduleEntryReservationDTO)obj;
         if (reservation.IsPresent != isPresent)
         {
             ReservationsOperationParam param = new ReservationsOperationParam();
             param.ReservationId = obj.GlobalId;
             param.OperationType = isPresent ? ReservationsOperationType.Presnet : ReservationsOperationType.Absent;
             return(param);
         }
         return(null);
     });
 }
Exemple #14
0
        public void Make_StatusCancelled()
        {
            entries[0].State = ScheduleEntryState.Cancelled;
            insertToDatabase(entries[0]);
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                Service.ReservationsOperation(data.Token, param);
            });
        }
Exemple #15
0
        public void Make_ReturnResults()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                var res             = Service.ReservationsOperation(data.Token, param);
                Assert.AreEqual(1, res.ScheduleEntry.Reservations.Count);
                Assert.AreEqual(res.Reservation.ScheduleEntryId, res.ScheduleEntry.GlobalId);
            });
        }
Exemple #16
0
        public void StatusCancelled()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.StatusCancelled;
                Service.ReservationsOperation(data.Token, param);
            });

            var db = Session.Get <ScheduleEntry>(entries[0].GlobalId);

            Assert.AreEqual(ScheduleEntryState.Cancelled, db.State);
        }
Exemple #17
0
        public void MakeReservation_ProductNameSet()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                Service.ReservationsOperation(data.Token, param);
            });

            var db = Session.Get <ScheduleEntry>(entries[0].GlobalId);

            Assert.AreEqual(string.Format("{0}:{1}", activities[0].Name, entries[0].StartTime), db.Reservations.ElementAt(0).Name);
        }
Exemple #18
0
        public void Payment_MakeReservation_WithoutPrice()
        {
            entries[0].Price = 0;
            insertToDatabase(entries[0]);

            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                var res             = Service.ReservationsOperation(data.Token, param);
                Assert.IsNull(res.Payment);
            });
        }
Exemple #19
0
        public void PayForReservation()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);
            ScheduleEntryReservationDTO reservation = null;

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                reservation         = service.ReservationsOperation(data.Token, param).Reservation;
            });



            var koszyk = new PaymentBasketDTO();

            koszyk.CustomerId = customers[0].GlobalId;
            koszyk.TotalPrice = 20m;
            var zakup = new PaymentDTO();

            zakup.Count   = 1;
            zakup.Product = reservation;
            koszyk.Payments.Add(zakup);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                koszyk = service.PaymentBasketOperation(data.Token, koszyk);
            });
            Assert.AreEqual(koszyk.GlobalId, koszyk.Payments[0].PaymentBasketId);
            GetScheduleEntriesParam param1 = new GetScheduleEntriesParam();

            param1.EntryId = entries[0].GlobalId;
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var entryData = service.GetScheduleEntries(data.Token, param1, new PartialRetrievingInfo());
                Assert.IsTrue(entryData.Items[0].Reservations.ElementAt(0).IsPaid);
            });
            var dbZakup = Session.Get <Payment>(koszyk.Payments[0].GlobalId);

            Assert.Greater(dbZakup.DateTime, DateTime.MinValue);
        }
Exemple #20
0
        public void MakePresentAbsent_StateDone()
        {
            entries[0].State = ScheduleEntryState.Planned;
            insertToDatabase(entries[0]);

            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);
            ReservationOperationResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                result = Service.ReservationsOperation(data.Token, param);
            });
            entries[0]       = Session.Get <ScheduleEntry>(entries[0].GlobalId);
            entries[0].State = ScheduleEntryState.Done;
            insertToDatabase(entries[0]);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.ReservationId = result.Reservation.GlobalId;
                param.OperationType = ReservationsOperationType.Presnet;
                result = Service.ReservationsOperation(data.Token, param);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.ReservationId = result.Reservation.GlobalId;
                param.OperationType = ReservationsOperationType.Absent;
                result = Service.ReservationsOperation(data.Token, param);
                Assert.IsNull(result.Reservation.EnterDateTime);
                Assert.IsNull(result.Reservation.LeaveDateTime);
            });
            var dbReservation = Session.Get <ScheduleEntryReservation>(result.Reservation.GlobalId);

            Assert.IsNull(dbReservation.EnterDateTime);
            Assert.IsNull(dbReservation.LeaveDateTime);
        }
        private void makeGroupReservation(ReservationsOperationParam param, ScheduleEntryBase dbEntry, Profile dbEmployee)
        {
            var dbGroup = Session.Get <CustomerGroup>(param.CustomerId.Value);

            if (dbGroup.Profile != dbEmployee || (dbEntry.Profile != dbEmployee))
            {
                throw new CrossProfileOperationException("CustomerGroup or ScheduleEntry belongs to another user");
            }

            foreach (var dbCustomer in dbGroup.Customers)
            {
                //get existing reservation for this customer. If he is on the list then skip this customer
                var dbReservation = dbEntry.Reservations.SingleOrDefault(x => x.Customer == dbCustomer && x.LeaveDateTime == null);
                if (dbReservation == null)
                {
                    dbReservation = makeReservation(dbEmployee, dbEntry, dbCustomer, dbReservation);
                    calculatePayement(dbReservation, false);
                }
            }
        }
Exemple #22
0
        public void MakeReservationTwiceForTheDifferentActivitiesByOneCustomer()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[0].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                Service.ReservationsOperation(data.Token, param);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                ReservationsOperationParam param = new ReservationsOperationParam();
                param.CustomerId    = customers[0].GlobalId;
                param.EntryId       = entries[3].GlobalId;
                param.OperationType = ReservationsOperationType.Make;
                Service.ReservationsOperation(data.Token, param);
            });
        }
 public ReservationOperationResult ReservationsOperation(Token token, ReservationsOperationParam param)
 {
     return(exceptionHandling(token, () => InternalService.ReservationsOperation(token, param)));
 }
        public ReservationOperationResult ReservationsOperation(ReservationsOperationParam param)
        {
            ReservationOperationResult result = new ReservationOperationResult();

            using (var trans = Session.BeginSaveTransaction())
            {
                var     dbEmployee    = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                var     dbReservation = param.ReservationId.HasValue ? Session.QueryOver <ScheduleEntryReservation>().Fetch(x => x.ScheduleEntry).Eager.Where(x => x.GlobalId == param.ReservationId).SingleOrDefault() : null;
                var     dbEntry       = param.EntryId.HasValue ? Session.Get <ScheduleEntryBase>(param.EntryId) : dbReservation.ScheduleEntry;
                Payment zakup         = null;
                if (param.OperationType == ReservationsOperationType.StatusDone)
                {
                    setStatus(dbEntry, ScheduleEntryState.Done);
                }
                else if (param.OperationType == ReservationsOperationType.StatusCancelled)
                {
                    setStatus(dbEntry, ScheduleEntryState.Cancelled);
                }
                else if (param.OperationType == ReservationsOperationType.MakeGroup)
                {
                    makeGroupReservation(param, dbEntry, dbEmployee);
                }
                else
                {
                    var dbCustomer = param.CustomerId.HasValue ? Session.Get <Customer>(param.CustomerId) : dbReservation.Customer;

                    if (dbCustomer.Profile != dbEmployee || (dbEntry.Profile != dbEmployee))
                    {
                        throw new CrossProfileOperationException("Customer or ScheduleEntry belongs to another user");
                    }

                    if (param.OperationType == ReservationsOperationType.Absent)
                    {
                        dbReservation.LeaveDateTime = dbReservation.EnterDateTime = null;
                    }
                    else if (param.OperationType == ReservationsOperationType.Presnet)
                    {
                        if (dbEntry.State != ScheduleEntryState.Done)
                        {
                            throw new InvalidOperationException("Absent can be only set for entries with Done status");
                        }
                        dbReservation.EnterDateTime = dbEntry.StartTime;
                        dbReservation.LeaveDateTime = dbEntry.EndTime;
                    }
                    else if (param.OperationType == ReservationsOperationType.Make)
                    {
                        //get existing reservation for this customer (except virtual customers)
                        if (!dbCustomer.IsVirtual)
                        {
                            dbReservation =
                                dbEntry.Reservations.SingleOrDefault(
                                    x => x.Customer == dbCustomer && x.LeaveDateTime == null);
                        }
                        dbReservation = makeReservation(dbEmployee, dbEntry, dbCustomer, dbReservation);
                        zakup         = calculatePayement(dbReservation, false);
                    }
                    else if (param.OperationType == ReservationsOperationType.Undo)
                    {
                        undoReservation(dbReservation, dbEntry);
                    }
                    Session.SaveOrUpdate(dbReservation);
                }

                Session.SaveOrUpdate(dbEntry);
                trans.Commit();
                result.Reservation   = Mapper.Map <ScheduleEntryReservation, ScheduleEntryReservationDTO>(dbReservation);
                result.ScheduleEntry = dbEntry.Map <ScheduleEntryBaseDTO>();
                result.Payment       = Mapper.Map <Payment, PaymentDTO>(zakup);
                //return result;
            }
            return(result);
        }