Ejemplo n.º 1
0
        public ScheduleSkuLine ExecuteItem()
        {
            using (DataContext context = DataContext.CreateForMessage(this))
            {
                SkuLine skuLine = context
                                  .SkuLineSet
                                  .Include("ChildCollection")
                                  .Include("ScheduleRule")
                                  .Where(x => x.Id == this.Id).SingleOrDefault();

                if (skuLine == null)
                {
                    throw new InvalidOperationException("SkuLine not found.");
                }

                return(new ScheduleSkuLine()
                {
                    Id = this.Id,
                    ProviderId = skuLine.ProviderId,
                    OwnerId = skuLine.Reservation.OwnerId,
                    PetId = skuLine.PetId.Value,
                    ReservationId = skuLine.ReservationId.Value,
                    EmployeeId = skuLine.ScheduleRule?.EmployeeId,
                    ScheduleRuleId = skuLine.ScheduleRuleId,
                    StartDate = skuLine.StartDate
                });
            }
        }
Ejemplo n.º 2
0
        public int ExecuteNonQuery()
        {
            using (DataContext context = DataContext.CreateForMessage(this))
            {
                // Step 1. Get primary skuLine
                SkuLine primarySkuLine = context
                                         .SkuLineSet
                                         .Include("ChildCollection")
                                         .Include("Reservation")
                                         .Where(x => x.Id == this.Id && x.ProviderId == this.ProviderId).SingleOrDefault();

                if (primarySkuLine == null)
                {
                    throw new InvalidOperationException("SkuLine not found.");
                }

                // Step 2. Add Skus
                foreach (Guid extraSkuId in this.ExtraSkuIdList)
                {
                    if (!primarySkuLine.ChildCollection.Any(x => x.SkuId == extraSkuId))
                    {
                        Sku extraSku = context.SkuSet.Where(x => x.Id == extraSkuId && x.ProviderId == this.ProviderId).SingleOrDefault();

                        context.SkuLineSet.Add(new SkuLine()
                        {
                            ProviderId  = this.ProviderId,
                            Name        = extraSku.Name,
                            Description = extraSku.Description,
                            Amount      = extraSku.Amount,
                            ParentId    = this.Id,
                            SkuId       = extraSkuId
                        });
                    }
                }

                // Step 3. Drop Skus
                foreach (SkuLine extraSkuLine in primarySkuLine.ChildCollection)
                {
                    if (!this.ExtraSkuIdList.Any(x => x == extraSkuLine.SkuId))
                    {
                        extraSkuLine.Voided = DateTime.UtcNow;
                    }
                }

                return(context.SaveChanges());
            }
        }
Ejemplo n.º 3
0
        public int ExecuteNonQuery()
        {
            using (DataContext context = DataContext.CreateForMessage(this))
            {
                // Step 1. Get SkuLine
                SkuLine skuLine = context.SkuLineSet.Where(x => x.Id == this.Id).SingleOrDefault();

                if (skuLine == null)
                {
                    throw new InvalidOperationException("SkuLine not found.");
                }

                // Step 2. Set ScheduleRuleId
                skuLine.ScheduleRuleId = this.ScheduleRuleId;
                skuLine.StartDate      = this.StartDate;

                return(context.SaveChanges());
            }
        }
Ejemplo n.º 4
0
        public ChooseExtras ExecuteItem()
        {
            using (DataContext context = DataContext.CreateForMessage(this))
            {
                SkuLine skuLine = context
                                  .SkuLineSet
                                  .Include("ChildCollection")
                                  .Where(x => x.Id == this.Id).SingleOrDefault();


                return(new ChooseExtras()
                {
                    Id = this.Id,
                    ProviderId = skuLine.ProviderId,
                    OwnerId = skuLine.Reservation.OwnerId,
                    PetId = skuLine.PetId.Value,
                    ReservationId = skuLine.ReservationId.Value,
                    SkuId = skuLine.SkuId,
                    ExtraSkuIdList = skuLine.ChildCollection.ToList().ConvertAll(x => x.SkuId)
                });
            }
        }
Ejemplo n.º 5
0
        public void GroomingAppointmentSmokeTest()
        {
            Guid     providerId      = new Guid("1543DD05-83D2-484D-9D59-16278995D4F1");
            DateTime appointmentDate = new DateTime(2019, 1, 7);

            Guid petId1  = new Guid("9de67d64-a67f-43b2-baed-9ca2981e50da");
            Guid petId2  = new Guid("3b796cbf-756d-4cc1-9e94-da4abe68c70c");
            Guid ownerId = new Guid("F5869C1B-90D0-4678-8F0F-AC9436AE41ED");

            // Step 1. Get Nav
            List <SkuCategory> skuCategoryList = new GetSkuCatetoryList()
            {
                ProviderId = providerId, PrimaryOnly = true, ShowDeleted = false
            }.ExecuteList();

            // Step 2. Choose 'Grooming' item
            SkuCategory skuCategory = skuCategoryList.Find(x => x.Name == "Grooming");

            // Step 3. Get Primary Sku's for 'Grooming'
            List <Sku> primarySkuList = new GetPrimarySkuList()
            {
                ProviderId = providerId, SkuCategoryId = skuCategory.Id
            }.ExecuteList();

            // Step 4. Choose 'Complete Groom-XL' item
            Sku sku = primarySkuList.Find(x => x.Name == "Complete Groom-XL");

            // Step 5.  Get Related Sku list
            List <Sku> relatedSkuList = new GetRelatedSkuList()
            {
                ProviderId = providerId, SkuId = sku.Id, Type = 1
            }.ExecuteList();

            // Step 6. Choose Related Sku's
            Sku extra1 = relatedSkuList.Find(x => x.Name == "FURminator Upgrade");
            Sku extra2 = relatedSkuList.Find(x => x.Name == "De-Matting");
            Sku extra3 = relatedSkuList.Find(x => x.Name == "Coconult Oil Silk Treatment");

            // Step 7. Get Employee List for Schedule Filter by Employee
            List <EmployeeInfo> employeeInfoList = new GetEmployeeInfoList()
            {
                ProviderId = providerId, IncludeTerminated = false
            }.ExecuteList();

            // Step 8. Choose Employee 'Elizabeth  Smith'
            EmployeeInfo employeeInfo = employeeInfoList.Find(x => x.FirstName.Trim() == "Elizabeth" && x.LastName.Trim() == "Smith");

            // Step 9. Get Rule List
            List <ScheduleRule> scheduleRuleList = new GetScheduleRuleList()
            {
                ProviderId = providerId
            }.ExecuteList();

            // Step 10. Get Filtered Rule List
            List <ScheduleRule> filteredRuleList = new GetFilteredScheduleRuleList()
            {
                ProviderId = providerId, EmployeeIdFilterList = new List <Guid>()
                {
                    employeeInfo.Id
                }
            }.ExecuteList();

            // Step 11. Get available days
            foreach (ScheduleRule scheduleRule in filteredRuleList)
            {
                for (int i = 0; i < 30; i++)
                {
                    // IsValid Date
                    bool isValidDate = scheduleRule.ValidDate(DateTime.Now.Date.AddDays(i));
                }
            }

            // Step 12. Get StartTimes for given date
            List <StartTime> startTimeList = filteredRuleList.GetStartTimeList(appointmentDate);

            // Step 13. Choose first start time
            StartTime startTime = startTimeList.First();

            // Step 14. Choose Rule
            ScheduleRule selectedRule = filteredRuleList.Find(x => x.Id == startTime.Id);

            // Step 15. Add Reservation
            AddReservation addReservation = new AddReservation()
            {
                Id            = Guid.NewGuid(),
                OwnerId       = ownerId,
                ProviderId    = providerId,
                SkuCategoryId = skuCategory.Id
            };

            // Step 16. Add Grooming Pet Reservation
            SkuLine skuLinePrimaryPet1 = new SkuLine()
            {
                ReservationId = addReservation.Id,
                ProviderId    = providerId,
                ParentId      = null,   // Primary
                PetId         = petId1, // Required for primary

                // Sku Memo
                SkuId       = sku.Id,
                Amount      = sku.Amount,
                Description = sku.Description,
                Name        = sku.Name,
                Quantity    = 1,

                // Schedule Rule/Block Memo ...
                ScheduleRuleId = selectedRule.Id,
                StartDate      = startTime.Time.Date,
                StartTime      = startTime.Time
            };

            // Step 17. Add Pet1 Extra1
            SkuLine skuLineExtra1Pet1 = new SkuLine()
            {
                ReservationId = addReservation.Id,
                ProviderId    = providerId,
                ParentId      = skuLinePrimaryPet1.Id, // Primary
                PetId         = null,                  // Required for primary

                // Sku Memo
                SkuId       = extra1.Id,
                Amount      = null,
                Description = extra1.Description,
                Name        = extra1.Name,
                Quantity    = 1
            };

            // Step 18. Add Pet1 Extra2
            SkuLine skuLineExtra2Pet1 = new SkuLine()
            {
                ReservationId = addReservation.Id,
                ProviderId    = providerId,
                ParentId      = skuLinePrimaryPet1.Id, // Primary
                PetId         = null,                  // Required for primary

                // Sku Memo
                SkuId       = extra2.Id,
                Amount      = null,
                Description = extra2.Description,
                Name        = extra2.Name,
                Quantity    = 1
            };


            // Step 19. Add Grooming Pet Reservation 2
            SkuLine skuLinePrimaryPet2 = new SkuLine()
            {
                ReservationId = addReservation.Id,
                ProviderId    = providerId,
                ParentId      = null,   // Primary
                PetId         = petId1, // Required for primary

                // Sku Memo
                SkuId       = sku.Id,
                Amount      = sku.Amount,
                Description = sku.Description,
                Name        = sku.Name,
                Quantity    = 1,

                // Schedule Rule/Block Memo ...
                ScheduleRuleId = selectedRule.Id,
                StartDate      = startTime.Time.Date,
                StartTime      = startTime.Time
            };

            // Step 20. Add Pet1 Extra1
            SkuLine skuLineExtra1Pet2 = new SkuLine()
            {
                ReservationId = addReservation.Id,
                ProviderId    = providerId,
                ParentId      = skuLinePrimaryPet2.Id, // Primary
                PetId         = null,                  // Required for primary

                // Sku Memo
                SkuId       = extra1.Id,
                Amount      = null,
                Description = extra1.Description,
                Name        = extra1.Name,
                Quantity    = 1
            };

            // Step 21. Add Pet1 Extra2
            SkuLine skuLineExtra2Pet2 = new SkuLine()
            {
                ReservationId = addReservation.Id,
                ProviderId    = providerId,
                ParentId      = skuLinePrimaryPet2.Id, // Primary
                PetId         = null,                  // Required for primary

                // Sku Memo
                SkuId       = extra2.Id,
                Amount      = null,
                Description = extra2.Description,
                Name        = extra2.Name,
                Quantity    = 1
            };

            // Step 23. Get CCToken (add option for swipe, nickname)
            //CCToken ccToken = new GetCCToken(){ OwnerId = ownerId }.ExecuteItem();

            //// Step 22. Send Payment (Amount == null means pay in full)
            //var addCCPaymentResult1 = new AddCCPayment() { Amount = null, ReservationId = addReservation.Id, CCToken = ccToken.Value }.ExecuteNonQuery();

            //// Step 23. Cancel Extra
            //new CancelSkuLine() { ReservationId = addReservation.Id, SkuLineId = skuLineExtra1Pet2.Id }.ExecuteNonQuery();

            //// Step 23. Send Payment (will Negative Value (Partial Refund))
            //var addCCPaymentResult2 = new AddCCPayment() { Amount = null, ReservationId = addReservation.Id, CCToken = ccToken.Value }.ExecuteNonQuery();

            //// Step 24. Add Extra
            //// new AddSkuLine() { ReservationId = addReservation.Id, SkuLineId = skuLineExtra1Pet2.Id }.ExecuteNonQuery();

            //// Step 25. Send Payment
            //var addCCPaymentResult3 = new AddCCPayment() { Amount = null, ReservationId = addReservation.Id, CCToken = ccToken.Value }.ExecuteNonQuery();

            //// Step 26. Reschedule Pet1
            //new RescheduleBlock() { SkuLineId = new List<Guid>(){ skuLinePrimaryPet1.Id,skuLinePrimaryPet2.Id},
            //    ScheduleRuleId = selectedRule.Id,
            //    StartDate = startTime.Date.AddDays(1),
            //    StartTime = startTime.AddDays.addReservation(1) }.ExecuteItem();


            //// Step 27. Cancel Reservation
            //new CancelReservation() { ReservationId = addReservation.Id }.ExecuteItem();


            //// Step 28. Send Payment (Full Refund)
            //var addCCPaymentResult3 = new AddCCPayment() { Amount = null, ReservationId = addReservation.Id, CCToken = ccToken.Value }.ExecuteNonQuery();
        }
Ejemplo n.º 6
0
        public int ExecuteNonQuery()
        {
            using (DataContext context = DataContext.CreateForMessage(this))
            {
                // Step 1. Create the reservation
                Reservation reservation = new Reservation();
                reservation.Id         = this.ReservationId;
                reservation.ProviderId = this.ProviderId;
                reservation.OwnerId    = this.OwnerId;

                context.ReservationSet.Add(reservation);

                // Step 2. Get ScheduleRuleId
                ScheduleRule scheduleRule = context.ScheduleRuleSet.Where(x => x.Id == this.ScheduleRuleId && x.ProviderId == this.ProviderId).SingleOrDefault();
                if (scheduleRule == null)
                {
                    throw new InvalidOperationException("Invalid schedule rule.");
                }

                // Step 2. Get Sku
                Sku sku = context.SkuSet.Where(x => x.Id == this.SkuId && x.ProviderId == this.ProviderId).SingleOrDefault();
                if (sku == null)
                {
                    throw new InvalidOperationException("SkuId not found.");
                }

                // Step 3. Create skuLine
                SkuLine skuLine = new SkuLine();
                skuLine.Id             = this.Id;
                skuLine.ProviderId     = this.ProviderId;
                skuLine.PetId          = this.PetId;
                skuLine.ReservationId  = this.ReservationId;
                skuLine.StartDate      = this.StartDate;
                skuLine.StartTime      = this.StartDate.AddHours(scheduleRule.StartTime.Value.Hour).AddMinutes(scheduleRule.StartTime.Value.Minute);
                skuLine.ScheduleRuleId = this.ScheduleRuleId;

                // Memo
                skuLine.SkuId       = sku.Id;
                skuLine.Name        = sku.Name;
                skuLine.Description = sku.Description;
                skuLine.Amount      = sku.Amount;

                context.SkuLineSet.Add(skuLine);

                //context.SaveChanges();

                // Step 4. Extras
                List <Sku> extraSkuList = context.SkuSet.Where(x => this.RelatedSkuIdList.Contains(x.Id) && x.ProviderId == this.ProviderId).ToList();

                foreach (Sku extraSku in extraSkuList)
                {
                    SkuLine extra = new SkuLine();
                    extra.ParentId      = skuLine.Id;
                    extra.ProviderId    = this.ProviderId;
                    extra.ReservationId = this.ReservationId;

                    // Memo
                    extra.SkuId       = extraSku.Id;
                    extra.Name        = extraSku.Name;
                    extra.Description = extraSku.Description;
                    extra.Amount      = extraSku.Amount;

                    context.SkuLineSet.Add(extra);
                }

                // Step 5. Save
                return(context.SaveChanges());
            }
        }
        public void GroomingReservationSmokeTest()
        {
            DateTime appointmentDate = new DateTime(2019, 2, 15);
            Guid     providerId      = new Guid("1543DD05-83D2-484D-9D59-16278995D4F1"); // WagRWC
            Guid     petId1          = new Guid("b5f6fb44-51ad-4635-8244-ec7a9bd19373");
//            Guid petId2 = new Guid("");
            Guid          ownerId           = new Guid("898c14c2-a865-4710-802a-a4e820319ed3");
            string        employeeFirstName = "Elizabeth";
            string        employeeLastName  = "Smith";
            List <string> addExtraSkuList   = new List <string>()
            {
                "FURminator Upgrade", "De-Matting", "Coconult Oil Silk Treatment"
            };


            // Step 1. Get Nav
            List <SkuCategory> skuCategoryList = new GetSkuCatetoryList()
            {
                ProviderId = providerId, PrimaryOnly = true, ShowDeleted = false
            }.ExecuteList();

            // Step 2. Choose 'Grooming' item
            SkuCategory skuCategory = skuCategoryList.Find(x => x.Name == "Grooming");

            // Step 3. Get Primary Sku's for 'Grooming'
            List <Sku> primarySkuList = new GetPrimarySkuList()
            {
                ProviderId = providerId, SkuCategoryId = skuCategory.Id
            }.ExecuteList();

            // Step 4. Choose 'Complete Groom-XL' item
            Sku sku = primarySkuList.Find(x => x.Name == "Complete Groom-XL");

            // Step 5.  Get Related Sku list
            List <Sku> relatedSkuList = new GetRelatedSkuList()
            {
                ProviderId = providerId, SkuId = sku.Id, Type = 1
            }.ExecuteList();

            // Step 6. Choose Related Sku's
            Sku extra1 = relatedSkuList.Find(x => x.Name == "FURminator Upgrade");
            Sku extra2 = relatedSkuList.Find(x => x.Name == "De-Matting");
            Sku extra3 = relatedSkuList.Find(x => x.Name == "Coconult Oil Silk Treatment");

            List <Sku> extraSkuList = relatedSkuList.FindAll(x => addExtraSkuList.Contains(x.Name));

            // Step 7. Get Employee List for Schedule Filter by Employee
            List <EmployeeInfo> employeeInfoList = new GetEmployeeInfoList()
            {
                ProviderId = providerId, IncludeTerminated = false
            }.ExecuteList();

            // Step 8. Choose Employee (ie. 'Elizabeth  Smith')
            EmployeeInfo employeeInfo = employeeInfoList.Find(x => x.FirstName.Trim().Equals(employeeFirstName, StringComparison.CurrentCultureIgnoreCase) && x.LastName.Trim().Equals(employeeLastName, StringComparison.CurrentCultureIgnoreCase));

            // Step 9. Get Rule List
            List <ScheduleRule> scheduleRuleList = new GetScheduleRuleList()
            {
                ProviderId = providerId
            }.ExecuteList();

            // Step 10. Get Filtered Rule List
            List <ScheduleRule> filteredRuleList = new GetFilteredScheduleRuleList()
            {
                ProviderId = providerId, EmployeeIdFilterList = new List <Guid>()
                {
                    employeeInfo.Id
                }
            }.ExecuteList();

            // Step 11. Get available days
            foreach (ScheduleRule scheduleRule in filteredRuleList)
            {
                for (int i = 0; i < 30; i++)
                {
                    // IsValid Date
                    bool isValidDate = scheduleRule.ValidDate(DateTime.Now.Date.AddDays(i));
                }
            }

            // Step 12. Get StartTimes for given date
            List <StartTime> startTimeList = filteredRuleList.GetStartTimeList(appointmentDate);

            // Step 13. Choose first start time
            StartTime startTime = startTimeList.First();

            // Step 14. Choose Rule
            ScheduleRule selectedRule = filteredRuleList.Find(x => x.Id == startTime.Id);

            // Step 15. Add Reservation
            AddReservation addReservation = new AddReservation()
            {
                Id            = Guid.NewGuid(),
                OwnerId       = ownerId,
                ProviderId    = providerId,
                SkuCategoryId = skuCategory.Id
            };

            // Step 16. Add Grooming Pet Reservation
            SkuLine skuLinePrimaryPet1 = new SkuLine()
            {
                ReservationId = addReservation.Id,
                ProviderId    = providerId,
                ParentId      = null,   // Primary
                PetId         = petId1, // Required for primary

                // Sku Memo
                SkuId       = sku.Id,
                Amount      = sku.Amount,
                Description = sku.Description,
                Name        = sku.Name,
                Quantity    = 1,

                // Schedule Rule/Block Memo ...
                ScheduleRuleId = selectedRule.Id,
                StartDate      = startTime.Time.Date,
                StartTime      = startTime.Time
            };

            // Step 17. Add Pet1 Extra1
            foreach (Sku extraSku in extraSkuList)
            {
                SkuLine extraSkuLine = new SkuLine()
                {
                    ReservationId = addReservation.Id,
                    ProviderId    = providerId,
                    ParentId      = skuLinePrimaryPet1.Id, // Primary
                    PetId         = null,                  // Required only for primary

                    // Sku Memo
                    SkuId       = extraSku.Id,
                    Amount      = extraSku.Amount,
                    Description = extraSku.Description,
                    Name        = extraSku.Name,
                    Quantity    = 1
                };
            }


            //// Step 19. Add Grooming Pet Reservation 2
            //SkuLine skuLinePrimaryPet2 = new SkuLine()
            //{
            //    ReservationId = addReservation.Id,
            //    ProviderId = providerId,
            //    ParentId = null, // Primary
            //    PetId = petId1, // Required for primary

            //    // Sku Memo
            //    SkuId = sku.Id,
            //    Amount = sku.Amount,
            //    Description = sku.Description,
            //    Name = sku.Name,
            //    Quantity = 1,

            //    // Schedule Rule/Block Memo ...
            //    ScheduleRuleId = selectedRule.Id,
            //    StartDate = startTime.Time.Date,
            //    StartTime = startTime.Time
            //};

            //// Step 20. Add Pet1 Extra1
            //SkuLine skuLineExtra1Pet2 = new SkuLine()
            //{
            //    ReservationId = addReservation.Id,
            //    ProviderId = providerId,
            //    ParentId = skuLinePrimaryPet2.Id, // Primary
            //    PetId = null, // Required for primary

            //    // Sku Memo
            //    SkuId = extra1.Id,
            //    Amount = null,
            //    Description = extra1.Description,
            //    Name = extra1.Name,
            //    Quantity = 1
            //};

            //// Step 21. Add Pet1 Extra2
            //SkuLine skuLineExtra2Pet2 = new SkuLine()
            //{
            //    ReservationId = addReservation.Id,
            //    ProviderId = providerId,
            //    ParentId = skuLinePrimaryPet2.Id, // Primary
            //    PetId = null, // Required for primary

            //    // Sku Memo
            //    SkuId = extra2.Id,
            //    Amount = null,
            //    Description = extra2.Description,
            //    Name = extra2.Name,
            //    Quantity = 1
            //};


            ////Step 23.Get CCToken(add option for swipe, nickname)
            //    CCToken ccToken = new GetCCToken() { OwnerId = ownerId }.ExecuteItem();

            //// Step 22. Send Payment (Amount == null means pay in full)
            //var addCCPaymentResult1 = new AddCCPayment() { Amount = null, ReservationId = addReservation.Id, CCToken = ccToken.Value }.ExecuteNonQuery();

            //// Step 23. Cancel Extra
            //new CancelSkuLine() { ReservationId = addReservation.Id, SkuLineId = skuLineExtra1Pet2.Id }.ExecuteNonQuery();

            //// Step 23. Send Payment (will Negative Value (Partial Refund))
            //var addCCPaymentResult2 = new AddCCPayment() { Amount = null, ReservationId = addReservation.Id, CCToken = ccToken.Value }.ExecuteNonQuery();

            //// Step 24. Add Extra
            //// new AddSkuLine() { ReservationId = addReservation.Id, SkuLineId = skuLineExtra1Pet2.Id }.ExecuteNonQuery();

            //// Step 25. Send Payment
            //var addCCPaymentResult3 = new AddCCPayment() { Amount = null, ReservationId = addReservation.Id, CCToken = ccToken.Value }.ExecuteNonQuery();

            //// Step 26. Reschedule Pet1
            //new RescheduleBlock()
            //{
            //    SkuLineId = new List<Guid>() { skuLinePrimaryPet1.Id, skuLinePrimaryPet2.Id },
            //    ScheduleRuleId = selectedRule.Id,
            //    StartDate = startTime.Date.AddDays(1),
            //    StartTime = startTime.AddDays.addReservation(1)
            //}.ExecuteItem();


            //// Step 27. Cancel Reservation
            //new CancelReservation() { ReservationId = addReservation.Id }.ExecuteItem();


            //// Step 28. Send Payment (Full Refund)
            //var addCCPaymentResult3 = new AddCCPayment() { Amount = null, ReservationId = addReservation.Id, CCToken = ccToken.Value }.ExecuteNonQuery();
        }