Ejemplo n.º 1
0
        public async Task CreateScheduleFromFileAsync(string name, Stream fileStream, CancellationToken cancellationToken = default(CancellationToken))
        {
            var schedule = new Schedule();

            schedule.ScheduleName  = name;
            schedule.OwningUser    = _httpContextAccessor.HttpContext.User.Identity.Name;
            schedule.ScheduleRules = new List <ScheduleRule>();

            using var reader = new StreamReader(fileStream);
            using var csv    = new CsvReader(reader, CultureInfo.InvariantCulture);

            var records = csv.GetRecords <ScheduleFileRow>();

            foreach (var record in records)
            {
                var rule = new ScheduleRule
                {
                    Name             = record.Name,
                    StartTime        = ScheduleRepresentationHelper.ConvertTimeStringToTimeSpan(record.StartTime),
                    EndTime          = ScheduleRepresentationHelper.ConvertTimeStringToTimeSpan(record.EndTime),
                    StartDate        = DateTime.Parse(record.StartDate).Date,
                    EndDate          = DateTime.Parse(record.EndDate).Date,
                    ScheduleRuleType = record.ScheduleRuleType,
                    DaysOfWeek       = ScheduleRepresentationHelper.ConvertStringToDaysOfWeekFlags(record.DaysOfWeek),
                    Url = record.Url
                };
                schedule.ScheduleRules.Add(rule);
            }

            _appDbContext.Schedules.Add(schedule);
            await _appDbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public void CheckRuleType()
        {
            Rule r = new OrRule();

            Assert.AreEqual("Or", r.RuleType);
            r = new ScheduleRule();
            Assert.AreEqual("Schedule", r.RuleType);
            r = new UserSelectionRule();
            Assert.AreEqual("UserSelection", r.RuleType);
        }
Ejemplo n.º 3
0
        public FeatureFlagState ScheduleRule(string p1, string p2, string currentDateTime)
        {
            var or = new ScheduleRule {
                From = DateTime.ParseExact(p1, "yyyy/MM/dd HH:mm", CultureInfo.InvariantCulture),
                To   = DateTime.ParseExact(p2, "yyyy/MM/dd HH:mm", CultureInfo.InvariantCulture)
            };

            return(or.Evaluate(new FeatureContext {
                DateTime = DateTime.ParseExact(currentDateTime, "yyyy/MM/dd HH:mm", CultureInfo.InvariantCulture)
            }));
        }
Ejemplo n.º 4
0
        public void AddScheduleRule()
        {
            // DEPENDENCIES
            _servSR = container.GetRequiredService <IScheduleRuleService>();

            // ARRANGE
            _sr = (ScheduleRule)Records.scheduleRule.Clone();

            // ACT
            _servSR.Create(_sr, _user);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the recurrent recordings
        /// </summary>
        /// <param name="cancellationToken">The CancellationToken</param>
        /// <returns></returns>
        public async Task <IEnumerable <SeriesTimerInfo> > GetSeriesTimersAsync(CancellationToken cancellationToken)
        {
            _logger.Info(string.Format("[ArgusTV] Start GetSeriesTimer Async"));
            await EnsureConnectionAsync(cancellationToken);

            List <SeriesTimerInfo> seriesTimerInfos = new List <SeriesTimerInfo>();

            try
            {
                List <UpcomingRecording> upcomingRecordings = Proxies.ControlService.GetAllUpcomingRecordings(UpcomingRecordingsFilter.Recordings).Result.GroupBy(u => u.Program.ScheduleId).Select(grp => grp.First()).ToList();

                foreach (UpcomingRecording upcomingRecording in upcomingRecordings)
                {
                    if (upcomingRecording != null && upcomingRecording.Program != null && upcomingRecording.Program.IsPartOfSeries)
                    {
                        var          schedule       = Proxies.SchedulerService.GetScheduleById(upcomingRecording.Program.ScheduleId).Result;
                        ScheduleRule daysOfWeekRule = schedule.Rules.SingleOrDefault(r => r.Type == ScheduleRuleType.DaysOfWeek);

                        var days = new List <DayOfWeek>();

                        if (daysOfWeekRule != null)
                        {
                            days = SchedulerHelper.GetDaysOfWeek((ScheduleDaysOfWeek)daysOfWeekRule.Arguments[0]);
                        }

                        seriesTimerInfos.Add(new SeriesTimerInfo
                        {
                            Id                 = upcomingRecording.Program.ScheduleId.ToString(),
                            ChannelId          = upcomingRecording.Program.Channel.ChannelId.ToString(),
                            Name               = upcomingRecording.Title,
                            Overview           = Proxies.GuideService.GetProgramById(Guid.Parse(upcomingRecording.Program.GuideProgramId.ToString())).Result.Description,
                            StartDate          = upcomingRecording.ActualStartTimeUtc,
                            ProgramId          = upcomingRecording.Program.GuideProgramId.ToString(),
                            EndDate            = upcomingRecording.ActualStopTimeUtc,
                            PostPaddingSeconds = upcomingRecording.Program.PostRecordSeconds,
                            PrePaddingSeconds  = upcomingRecording.Program.PreRecordSeconds,
                            Days               = days
                        });
                    }
                }

                UtilsHelper.DebugInformation(_logger, string.Format("[ArgusTV] GetSeriesTimers with the following TimerInfo: {0}", _jsonSerializer.SerializeToString(seriesTimerInfos)));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("[ArgusTV] GetSeriesTimers async failed", ex);
                throw new LiveTvConflictException();
            }


            return(seriesTimerInfos);
        }
Ejemplo n.º 6
0
        public ImportSchedule Convert(List <string> errors)
        {
            Schedule schedule = new Schedule();

            schedule.IsActive          = this.IsActive;
            schedule.Name              = this.Name;
            schedule.ChannelType       = this.ChannelType;
            schedule.KeepUntilMode     = this.KeepUntilMode;
            schedule.KeepUntilValue    = this.KeepUntilValue;
            schedule.PreRecordSeconds  = this.PreRecordSeconds;
            schedule.PostRecordSeconds = this.PostRecordSeconds;
            schedule.SchedulePriority  = this.SchedulePriority;
            schedule.ScheduleType      = this.ScheduleType;
            foreach (ScheduleRule rule in this.Rules)
            {
                if (rule.Type == ScheduleRuleType.TvChannels)
                {
                    rule.Type = ScheduleRuleType.Channels; /* For backwards compatibility. */
                }
                if (rule.Type == ScheduleRuleType.Channels ||
                    rule.Type == ScheduleRuleType.NotOnChannels)
                {
                    List <Guid> tvChannelIds = new List <Guid>();
                    foreach (string channelName in rule.Arguments)
                    {
                        Channel tvChannel = Proxies.SchedulerService.GetChannelByDisplayName(schedule.ChannelType, channelName).Result;
                        if (tvChannel == null)
                        {
                            errors.Add(String.Format(CultureInfo.CurrentCulture, "Channel '{0}' not found.", channelName));
                        }
                        else
                        {
                            tvChannelIds.Add(tvChannel.ChannelId);
                        }
                    }
                    if (tvChannelIds.Count > 0)
                    {
                        ScheduleRule channelsRule = new ScheduleRule(rule.Type);
                        foreach (Guid tvChannelId in tvChannelIds)
                        {
                            channelsRule.Arguments.Add(tvChannelId);
                        }
                        schedule.Rules.Add(channelsRule);
                    }
                }
                else
                {
                    schedule.Rules.Add(rule);
                }
            }
            return(new ImportSchedule(schedule, _history.ToArray()));
        }
Ejemplo n.º 7
0
        private static void AppendStringArgumentsRule(List <ScheduleRule> rules, ScheduleRuleType ruleType, IList arguments)
        {
            ScheduleRule rule = new ScheduleRule(ruleType);

            foreach (string arg in arguments)
            {
                rule.Arguments.Add(arg);
            }
            if (rule.Arguments.Count > 0)
            {
                rules.Add(rule);
            }
        }
Ejemplo n.º 8
0
        public void AppendChannelsRule(List <ScheduleRule> rules, bool notOnChannels, IList channelIds)
        {
            ScheduleRule channelsRule = new ScheduleRule(notOnChannels ? ScheduleRuleType.NotOnChannels : ScheduleRuleType.Channels);

            foreach (Guid channel in channelIds)
            {
                channelsRule.Arguments.Add(channel);
            }
            if (channelsRule.Arguments.Count > 0)
            {
                rules.Add(channelsRule);
            }
        }
Ejemplo n.º 9
0
        public FluentRecordBase AddScheduleRule(
            )
        {
            //
            // DEPENDENCIES
            _servSR = container.Resolve <IScheduleRuleService>();

            //
            // ARRANGE
            _sr = (ScheduleRule)Records.scheduleRule.Clone();

            //
            // ACT
            _servSR.Create(_sr, _user);
            return(this);
        }
Ejemplo n.º 10
0
        public void TestInitialize()
        {
            _savedScheduleRule = new ScheduleRule();
            _fakeScheduleRule  = new ScheduleRule()
            {
                day         = 1,
                leadHours   = 48,
                maxEndMin   = 30,
                minStartMin = 1,
                ID          = 1
            };
            _fakeScheduleRules = new List <ScheduleRule>();
            _fakeScheduleRules.Add(_fakeScheduleRule);
            _fakeScheduleRules.Add(new ScheduleRule()
            {
                day         = 1,
                leadHours   = 45,
                maxEndMin   = 20,
                minStartMin = 2,
                ID          = 2
            });

            _scheduleRuleServ = new Mock <IScheduleRuleService>();
            _scheduleRuleServ.Setup(s => s.GetAll())
            .Returns(_fakeScheduleRules.AsQueryable);
            _scheduleRuleServ.Setup(s => s.Get(1000))
            .Returns((ScheduleRule)null);
            _scheduleRuleServ.Setup(s => s.Get(1))
            .Returns(_fakeScheduleRule);
            _scheduleRuleServ.Setup(s => s.Create(It.IsAny <ScheduleRule>(), It.IsAny <string>()))
            .Returns(_fakeScheduleRule);
            _scheduleRuleServ.Setup(s => s.Save(It.Is <ScheduleRule>(r => r.ID == 1), It.IsAny <string>()))
            .Callback((ScheduleRule sr, string user) => _savedScheduleRule = sr);
            _scheduleRuleServ.Setup(s => s.Delete(1, It.IsAny <string>()))
            .Verifiable();
            _scheduleRuleServ.Setup(s => s.Delete(1000, It.IsAny <string>()))
            .Verifiable();

            var mapperConfig = new MapperConfiguration(config =>
            {
                config.ConfigureApi();
            });

            _mapper = mapperConfig.CreateMapper();

            _controller = new ScheduleRulesController(_scheduleRuleServ.Object, _mapper);
        }
Ejemplo n.º 11
0
        public FluentRecordBase AddScheduleRule(
            )
        {
            //
            // DEPENDENCIES
            if (_servTR == null)
            {
                AddServScheduleRule();
            }

            //
            // ARRANGE
            _sr = (ScheduleRule)Records.scheduleRule.Clone();

            //
            // ACT
            _servSR.Create(_sr, _user);
            return(this);
        }
Ejemplo n.º 12
0
 public ExportSchedule(Schedule schedule)
 {
     _isActive          = schedule.IsActive;
     _name              = schedule.Name;
     _channelType       = schedule.ChannelType;
     _keepUntilMode     = schedule.KeepUntilMode;
     _keepUntilValue    = schedule.KeepUntilValue;
     _preRecordSeconds  = schedule.PreRecordSeconds;
     _postRecordSeconds = schedule.PostRecordSeconds;
     _schedulePriority  = schedule.SchedulePriority;
     _scheduleType      = schedule.ScheduleType;
     foreach (ScheduleRule rule in schedule.Rules)
     {
         if (rule.Type == ScheduleRuleType.Channels ||
             rule.Type == ScheduleRuleType.NotOnChannels)
         {
             List <string> channelNames = new List <string>();
             foreach (Guid channelId in rule.Arguments)
             {
                 Channel channel = Proxies.SchedulerService.GetChannelById(channelId).Result;
                 if (channel != null)
                 {
                     channelNames.Add(channel.DisplayName);
                 }
             }
             if (channelNames.Count > 0)
             {
                 ScheduleRule channelsRule = new ScheduleRule(rule.Type);
                 foreach (string channelName in channelNames)
                 {
                     channelsRule.Arguments.Add(channelName);
                 }
                 _rules.Add(channelsRule);
             }
         }
         else
         {
             _rules.Add(rule);
         }
     }
     _history = new List <ScheduleRecordedProgram>(Proxies.ControlService.GetPreviouslyRecordedHistory(schedule.ScheduleId).Result);
 }
Ejemplo n.º 13
0
        public ScheduleBlock GetScheduleBlock(Guid id, Guid ruleId, DateTime start)
        {
            ScheduleBlock scheduleBlock = GetScheduleBlock(id);

            if (scheduleBlock != null)
            {
                return(scheduleBlock);
            }

            //TODO: Attempt to get it from db

            // Create new
            ScheduleRule scheduleRule = this.ScheduleRuleList.Find(x => x.Id == ruleId);

            return(new ScheduleBlock()
            {
                Id = id,
                EmployeeId = scheduleRule.EmployeeId,
                Start = start,
                End = new DateTime(start.Year, start.Month, start.Day, scheduleRule.EndHour.Value, scheduleRule.EndMinute.Value, 0),
            });
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 16
0
        private void UpdateDateTime()
        {
            DateTime     time        = DateTime.Now;
            Schedule     sched       = null;
            ScheduleRule _manualRule = null;
            int          valueYear   = 0;
            bool         yearFound   = true;

            if (_upcomingProgram != null)
            {
                sched = Proxies.SchedulerService.GetScheduleById(_upcomingProgram.ScheduleId).Result;
                if (sched != null)
                {
                    yearFound   = false;
                    _manualRule = sched.Rules.FindRuleByType(ScheduleRuleType.ManualSchedule);
                    if (_manualRule != null)
                    {
                        time = Convert.ToDateTime(_manualRule.Arguments[0]);
                    }
                }
            }

            for (int i = DateTime.Now.Year; i <= DateTime.Now.Year + 2; i++)
            {
                _spinStartYear.AddLabel(i.ToString(), 0);
                if (_upcomingProgram != null && sched != null && yearFound == false)
                {
                    if (i.ToString() == time.Year.ToString())
                    {
                        yearFound = true;
                    }
                    valueYear++;
                }
            }

            if (yearFound == false)
            {
                // year not found in list, add year in list
                _spinStartYear.AddLabel(time.ToString(), 0);
                yearFound = true;
                valueYear++;
            }

            for (int i = 1; i <= 12; i++)
            {
                if (i < 10)
                {
                    _spinStartMonth.AddLabel("0" + i.ToString(), 0);
                }
                else
                {
                    _spinStartMonth.AddLabel(i.ToString(), 0);
                }
            }

            UpdateDaysinMonth(Int32.Parse(_spinStartMonth.GetLabel()), Int32.Parse(_spinStartYear.GetLabel()));

            for (int i = 0; i <= 23; i++)
            {
                if (i < 10)
                {
                    _spinStartHour.AddLabel("0" + i.ToString(), 0);
                    _spinHoursDuration.AddLabel("0" + i.ToString(), 0);
                }
                else
                {
                    _spinStartHour.AddLabel(i.ToString(), 0);
                    _spinHoursDuration.AddLabel(i.ToString(), 0);
                }
            }

            for (int i = 0; i <= 59; i++)
            {
                if (i < 10)
                {
                    _spinStartMinute.AddLabel("0" + i.ToString(), 0);
                    _spinMinutesDuration.AddLabel("0" + i.ToString(), 0);
                }
                else
                {
                    _spinStartMinute.AddLabel(i.ToString(), 0);
                    _spinMinutesDuration.AddLabel(i.ToString(), 0);
                }
            }

            _spinStartMonth.Value  = (time.Month - 1);
            _spinStartDay.Value    = (time.Day - 1);
            _spinStartHour.Value   = time.Hour;
            _spinStartMinute.Value = time.Minute;

            if (_upcomingProgram != null && sched != null && _manualRule != null)
            {
                if (yearFound)
                {
                    _spinStartYear.Value = (valueYear - 1);
                }
                _spinHoursDuration.Value   = _upcomingProgram.Duration.Hours;
                _spinMinutesDuration.Value = _upcomingProgram.Duration.Minutes;
            }
            else
            {
                //default duration = 1 hour
                _spinHoursDuration.Value   = 1;
                _spinMinutesDuration.Value = 0;
            }
        }
Ejemplo n.º 17
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();
        }