Beispiel #1
0
        public BusinessHours AddBusinessHours(BusinessHours businessHours)
        {
            _context.BusinessHours.Add(businessHours);
            _context.SaveChanges();

            return(businessHours);
        }
        public ActionResult Create(CreatePoiViewModel poi)
        {
            if (ModelState.IsValid)
            {
                var b = new BusinessHours {
                    FromHour = poi.BusinessHoursFromHour.Value, ToHour = poi.BusinessHoursToHour.Value
                };

                var newPoi = new PointOfInterest(poi.LocationId, poi.Description, b, poi.TimeTovisit.Value, identity.GetUserId());


                if (!string.IsNullOrEmpty(poi.Hashtags))
                {
                    var hashtags = poi.Hashtags.Split(',');

                    foreach (var tag in hashtags)
                    {
                        newPoi.Hashtags.Add(new Hashtag {
                            UserId = newPoi.UserId, Tag = tag
                        });
                    }
                }

                unitOfWork.PoiRepository.Insert(newPoi);
                unitOfWork.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(poi));
        }
        public void CanCreateStoreHours()
        {
            using (var session = _sessionFactory.OpenSession())
            {
                using (var trx = session.BeginTransaction())
                {
                    var h1 = new BusinessHours
                    {
                        Name = "Westridge Kiosk",
                        StartOfWeek = new DateTime(2016, 1, 11),
                        EndOfWeek = new DateTime(2016, 1, 17),
                        Hours = new List<BusinessDay> { GetBusinessDay(11, 9, 17), GetBusinessDay(13, 9, 17) }
                    };

                    var h2 = new BusinessHours
                    {
                        Name = "Hunters Ridge",
                        StartOfWeek = new DateTime(2016, 1, 11),
                        EndOfWeek = new DateTime(2016, 1, 17),
                        Hours = new List<BusinessDay> { GetBusinessDay(12, 13, 17) }
                    };

                    session.Save(h1);
                    session.Save(h2);
                    trx.Commit();
                }
            }
           
        }
Beispiel #4
0
        public int?AddBusinessHours(BusinessHours businessHours, List <BusinessHoursDetails> listBusinessHoursDetails)
        {
            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    _context.BusinessHours.Add(businessHours);
                    _context.SaveChanges();

                    var businessHoursId = businessHours.BusinessHoursId;

                    foreach (var businessHoursDetail in listBusinessHoursDetails)
                    {
                        businessHoursDetail.BusinessHoursId = businessHoursId;
                        _context.BusinessHoursDetails.Add(businessHoursDetail);
                        _context.SaveChanges();
                    }



                    dbContextTransaction.Commit();
                    return(1);
                }
                catch (Exception)
                {
                    dbContextTransaction.Rollback();
                    return(0);
                }
            }
        }
        public void CanCreateStoreHours()
        {
            using (var session = _sessionFactory.OpenSession())
            {
                using (var trx = session.BeginTransaction())
                {
                    var h1 = new BusinessHours
                    {
                        Name        = "Westridge Kiosk",
                        StartOfWeek = new DateTime(2016, 1, 11),
                        EndOfWeek   = new DateTime(2016, 1, 17),
                        Hours       = new List <BusinessDay> {
                            GetBusinessDay(11, 9, 17), GetBusinessDay(13, 9, 17)
                        }
                    };

                    var h2 = new BusinessHours
                    {
                        Name        = "Hunters Ridge",
                        StartOfWeek = new DateTime(2016, 1, 11),
                        EndOfWeek   = new DateTime(2016, 1, 17),
                        Hours       = new List <BusinessDay> {
                            GetBusinessDay(12, 13, 17)
                        }
                    };

                    session.Save(h1);
                    session.Save(h2);
                    trx.Commit();
                }
            }
        }
Beispiel #6
0
        public override double CalculateDuration()
        {
            var startTime = BusinessHours.GetStartOfChargePeriod(Start);
            var endTime   = BusinessHours.GetEndOfChargePeriod(End);

            if (!BusinessHours.IsChargeableStay(Start, End))
            {
                return(0);
            }

            if (Start.Date == End.Date)
            {
                return((endTime - startTime).TotalMinutes);
            }

            var endOfStartDay          = BusinessHours.GetEndOfChargeableDay(startTime);
            var startOfEndDay          = BusinessHours.GetStartOfChargeableDay(endTime);
            var minsUsedInStartDay     = (endOfStartDay - startTime).TotalMinutes;
            var minsUsedInEndDay       = (endTime - startOfEndDay).TotalMinutes;
            var businessHoursInMinutes = ((BusinessHours.EndHour - BusinessHours.StartHour) * 60) + (BusinessHours.EndMinute - BusinessHours.StartMinute);
            var totalUsedMinutes       = minsUsedInStartDay + minsUsedInEndDay;

            for (DateTime day = startTime.AddDays(1); day < endTime.AddDays(-1); day = day.AddDays(1))
            {
                totalUsedMinutes += businessHoursInMinutes;
            }

            return(totalUsedMinutes);
        }
Beispiel #7
0
        public HashtagRepositoryMock()
        {
            var b = new BusinessHours {
                FromHour = new TimeSpan(9, 0, 0), ToHour = new TimeSpan(17, 59, 58)
            };

            user = new User()
            {
                Id          = Guid.NewGuid().ToString(),
                UserName    = "******",
                Email       = "*****@*****.**",
                DisplayName = "Administrator"
            };

            coords = new GpsCoordinate
            {
                Id        = 129557542,
                Altitude  = 0,
                Latitude  = 41.1454754,
                Longitude = -8.6155655
            };

            location = new Location("Torre dos Clérigos", coords);
            poi      = new PointOfInterest(location, "Mock POI", b, 3, user);

            Setup();
        }
Beispiel #8
0
        public bool IsInBusinessTime(DateTime dateTime)
        {
            var dayOfWeek = dateTime.DayOfWeek;
            var hour      = dateTime.Hour;

            return(BusinessHours.Any(b => b.DayOfWeek == dayOfWeek &&
                                     hour >= b.HourFrom &&
                                     hour < b.HourTo));
        }
        public override double CalculateDuration()
        {
            if (!BusinessHours.IsChargeableStay(Start, End))
            {
                return(0);
            }
            var totalDays = (BusinessHours.GetEndOfDay(End) - BusinessHours.GetStartOfDay(Start)).TotalDays;

            return(Math.Ceiling(totalDays));
        }
Beispiel #10
0
        public BusinessHours GetBusinessHours(int id)
        {
            BusinessHours businessHours = _context.BusinessHours.Find(id);

            if (businessHours == null)
            {
                return(null);
            }
            return(businessHours);
        }
        // HELPER FUNCTION 4
        // THIS FUNCTION INSERTS THE BUSINESS HOURS IN A LIST EACH INDEX
        // REPRESENT A WEEKDAY
        private void SetListOfBusinessDeliveryHours(string hoursStr)
        {
            BusinessHours hours = JsonConvert.DeserializeObject <BusinessHours>(hoursStr);

            businessDeliveryHours.Add(hours.Sunday);
            businessDeliveryHours.Add(hours.Monday);
            businessDeliveryHours.Add(hours.Tuesday);
            businessDeliveryHours.Add(hours.Wednesday);
            businessDeliveryHours.Add(hours.Thursday);
            businessDeliveryHours.Add(hours.Friday);
            businessDeliveryHours.Add(hours.Saturday);
        }
Beispiel #12
0
        public void Delete(BusinessHours businessHours)
        {
            BusinessHours existing = _context.BusinessHours.Find(businessHours.BusinessHoursId);

            if (existing == null)
            {
                throw new ArgumentNullException($"Could not find business hours by ID {businessHours.BusinessHoursId}");
            }

            _context.BusinessHours.Remove(existing);
            _context.SaveChanges();
        }
Beispiel #13
0
        //private void SeedLocations(PortoGoContext context)
        //{
        //    context.Locations.AddOrUpdate(
        //        p => p.Name,
        //        new Location("Torre dos Clérigos", 41.1456753f, -8.614598500000056f),
        //        new Location("ISEP", 41.17784570000001f, -8.608100599999943f),
        //        new Location("Estação de São Bento", 41.1442942f, -8.61059350000005f),
        //        new Location("Estação de Campanhã", 41.1487999f, -8.585402299999942f),
        //        new Location("Teste-25449245", 41.1471851f, -8.5853787f),
        //        new Location("Teste-25449246", 41.1477198f, -8.5852170f),
        //        new Location("Teste-25449247", 41.1507225f, -8.5845591f),
        //        new Location("Teste-25449250", 41.1541300f, -8.5840688f),
        //        new Location("Teste-25449251", 41.1567511f, -8.5832999f),
        //        new Location("Teste-25449255", 41.1638290f, -8.5802570f),
        //        new Location("Teste-25449257", 41.1657318f, -8.5783023f),
        //        new Location("Teste-25449258", 41.1757128f, -8.5668188f),
        //        new Location("Teste-25449261", 41.1831167f, -8.5583031f),
        //        new Location("Teste-25449262", 41.1840308f, -8.5575022f),
        //        new Location("Teste-25449263", 41.1850770f, -8.5568476f),
        //        new Location("Teste-25449264", 41.1865640f, -8.5563026f),
        //        new Location("Teste-25449265", 41.1887762f, -8.5555515f),
        //        new Location("Teste-25449267", 41.1895190f, -8.5553584f),
        //        new Location("Teste-25449269", 41.1903264f, -8.5553155f),
        //        new Location("Teste-25449271", 41.1913922f, -8.5553799f),
        //        new Location("Teste-25449273", 41.1976618f, -8.5560299f),
        //        new Location("Teste-25449279", 41.1993144f, -8.5562148f),
        //        new Location("Teste-25449280", 41.2001396f, -8.5563647f),
        //        new Location("Teste-25449281", 41.2036967f, -8.5572912f),
        //        new Location("Teste-25449282", 41.2052824f, -8.5575470f),
        //        new Location("Teste-25449283", 41.2063589f, -8.5574827f),
        //        new Location("Teste-25503936", 41.1659814f, -8.6405050f),
        //        new Location("Teste-25503937", 41.1663352f, -8.6407599f),
        //        new Location("Teste-25503938", 41.1665984f, -8.6406541f),
        //        new Location("Teste-25503940", 41.1673010f, -8.6404167f),
        //        new Location("Teste-25503943", 41.1683007f, -8.6403026f),
        //        new Location("Teste-25503951", 41.1683470f, -8.6420446f),
        //        new Location("Teste-25503952", 41.1682238f, -8.6424873f),
        //        new Location("Teste-25503953", 41.1681519f, -8.6427092f),
        //        new Location("Teste-25503962", 41.1677439f, -8.6438248f),
        //        new Location("Teste-25503963", 41.1675709f, -8.6438606f),
        //        new Location("Teste-25503965", 41.1672801f, -8.6438177f),
        //        new Location("Teste-25503966", 41.1670819f, -8.6436726f),
        //        new Location("Teste-25503967", 41.1668521f, -8.6435160f),
        //        new Location("Teste-25503969", 41.1665997f, -8.6434938f),
        //        new Location("Teste-25503970", 41.1663142f, -8.6437907f),
        //        new Location("Teste-25503977", 41.1659322f, -8.6414200f),
        //        new Location("Teste-25503993", 41.1669295f, -8.6428465f),
        //        new Location("Teste-25503994", 41.1669617f, -8.6431414f),
        //        new Location("Teste-25503995", 41.1670147f, -8.6432498f),
        //        new Location("Teste-25503996", 41.1672823f, -8.6435503f),
        //        new Location("Teste-25503998", 41.1675207f, -8.6435717f),
        //        new Location("Teste-25503999", 41.1676499f, -8.6434218f),
        //        new Location("Teste-25504000", 41.1676979f, -8.6431748f),
        //        new Location("Teste-25504002", 41.1676804f, -8.6430669f),
        //        new Location("Teste-25504003", 41.1676312f, -8.6424866f),
        //        new Location("Teste-25504005", 41.1678815f, -8.6426046f),
        //        new Location("Teste-25504006", 41.1680965f, -8.6425191f),
        //        new Location("Teste-25504007", 41.1682332f, -8.6422727f),
        //        new Location("Teste-25504008", 41.1682170f, -8.6419616f),
        //        new Location("Teste-25504010", 41.1680797f, -8.6417363f),
        //        new Location("Teste-25504011", 41.1678718f, -8.6416642f),
        //        new Location("Teste-25504013", 41.1676392f, -8.6417929f),
        //        new Location("Teste-25504017", 41.1674806f, -8.6411798f),
        //        new Location("Teste-25504018", 41.1673868f, -8.6408185f),
        //        new Location("Teste-25504021", 41.1671886f, -8.6406898f),
        //        new Location("Teste-25504024", 41.1669070f, -8.6407815f),
        //        new Location("Teste-25504025", 41.1667713f, -8.6411247f),
        //        new Location("Teste-25504027", 41.1668241f, -8.6414316f),
        //        new Location("Teste-25504120", 41.1762333f, -8.6225925f),
        //        new Location("Teste-25504123", 41.1755536f, -8.6224240f),
        //        new Location("Teste-25504126", 41.1749160f, -8.6228025f),
        //        new Location("Teste-25504135", 41.1745264f, -8.6225730f),
        //        new Location("Teste-25504141", 41.1728439f, -8.6223490f),
        //        new Location("Teste-25504147", 41.1724849f, -8.6224639f),
        //        new Location("Teste-25504151", 41.1722948f, -8.6227460f),
        //        new Location("Teste-25504153", 41.1722948f, -8.6231859f),
        //        new Location("Teste-25504154", 41.1724805f, -8.6234970f),
        //        new Location("Teste-25504156", 41.1728439f, -8.6235721f),
        //        new Location("Teste-25504157", 41.1731439f, -8.6233222f),
        //        new Location("Teste-25504158", 41.1732085f, -8.6231591f),
        //        new Location("Teste-25504163", 41.1746710f, -8.6224487f),
        //        new Location("Teste-25504164", 41.1742772f, -8.6223748f),
        //        new Location("Teste-25504165", 41.1727167f, -8.6220456f),
        //        new Location("Teste-25504166", 41.1725112f, -8.6221063f),
        //        new Location("Teste-25504167", 41.1721596f, -8.6225438f),
        //        new Location("Teste-25504168", 41.1720932f, -8.6228926f),
        //        new Location("Teste-25504169", 41.1723485f, -8.6235747f),
        //        new Location("Teste-25504170", 41.1726560f, -8.6240516f),
        //        new Location("Teste-25504171", 41.1728750f, -8.6246354f),
        //        new Location("Teste-25504172", 41.1729503f, -8.6251884f),
        //        new Location("Teste-25504173", 41.1729371f, -8.6255381f),
        //        new Location("Teste-25504174", 41.1746091f, -8.6232340f),
        //        new Location("Teste-25504175", 41.1743320f, -8.6237194f),
        //        new Location("Teste-25504176", 41.1737495f, -8.6240683f),
        //        new Location("Teste-25504177", 41.1734635f, -8.6243241f),
        //        new Location("Teste-25504178", 41.1733707f, -8.6245069f),
        //        new Location("Teste-25504179", 41.1737301f, -8.6206520f),
        //        new Location("Teste-25504180", 41.1737976f, -8.6213756f),
        //        new Location("Teste-25504181", 41.1740318f, -8.6218803f),
        //        new Location("Teste-25504182", 41.1744024f, -8.6222471f),
        //        new Location("Teste-25504183", 41.1748294f, -8.6223575f),
        //        new Location("Teste-25507436", 41.1206037f, -8.5725049f),
        //        new Location("Teste-25507437", 41.1206983f, -8.5723830f),
        //        new Location("Teste-25507438", 41.1199688f, -8.5723428f),
        //        new Location("Teste-25507439", 41.1199426f, -8.5721899f),
        //        new Location("Teste-25507440", 41.1187541f, -8.5721852f),
        //        new Location("Teste-25507441", 41.1187710f, -8.5720409f),
        //        new Location("Teste-25507442", 41.1175723f, -8.5720504f),
        //        new Location("Teste-25507443", 41.1176111f, -8.5719041f),
        //        new Location("Teste-25507444", 41.1170247f, -8.5719539f),
        //        new Location("Teste-25507445", 41.1168190f, -8.5717512f),
        //        new Location("Teste-25507446", 41.1158770f, -8.5715006f),
        //        new Location("Teste-25507447", 41.1159723f, -8.5713811f),
        //        new Location("Teste-25507448", 41.1150363f, -8.5708998f),
        //        new Location("Teste-25507449", 41.1150974f, -8.5707638f),
        //        new Location("Teste-25507450", 41.1129913f, -8.5690383f),
        //        new Location("Teste-25507451", 41.1131894f, -8.5690490f),
        //        new Location("Teste-25507452", 41.1117606f, -8.5679171f),
        //        new Location("Teste-25507453", 41.1117722f, -8.5677618f),
        //        new Location("Teste-25507454", 41.1103460f, -8.5666350f),
        //        new Location("Teste-25507455", 41.1104015f, -8.5664999f),
        //        new Location("Teste-25507456", 41.1096508f, -8.5661576f),
        //        new Location("Teste-25507457", 41.1097579f, -8.5660691f),
        //        new Location("Teste-25507459", 41.1089125f, -8.5656699f),
        //        new Location("Teste-25507550", 41.1663546f, -8.5838349f)

        //    );
        //}

        private void SeedPoi(PortoGoContext context)
        {
            var b = new BusinessHours {
                FromHour = new TimeSpan(9, 0, 0), ToHour = new TimeSpan(17, 59, 59)
            };

            var user = context.Users.Where(x => x.UserName == "admin").FirstOrDefault();

            context.PointsOfInterest.AddOrUpdate(
                p => p.LocationId,
                new PointOfInterest(1, "Placa junto à Torre dos Clérigos", b, 2.5, user),
                new PointOfInterest(2, "Edificio H", b, 6, user)
                );
        }
Beispiel #14
0
        public static TimeSpan CalculatePausedTime(int ticketId,
                                                   Organization organization,
                                                   BusinessHours businessHours,
                                                   SlaTrigger slaTrigger,
                                                   List <DateTime> daysToPause,
                                                   CalendarEvents holidays,
                                                   LoginUser loginUser,
                                                   Dictionary <int, double> businessPausedTimes,
                                                   Logs logs = null,
                                                   bool overwritePrevious = false,
                                                   DateTime?startOn       = null)
        {
            TimeSpan       totalPausedTime = new TimeSpan();
            SlaPausedTimes slaPausedTimes  = new SlaPausedTimes(loginUser);

            slaPausedTimes.LoadByTicketId(ticketId, startOn);

            foreach (SlaPausedTime slaPausedTime in slaPausedTimes)
            {
                bool hasBeenCalculated = slaPausedTime.BusinessPausedTime != null;

                if (!hasBeenCalculated || (hasBeenCalculated && overwritePrevious))
                {
                    TimeSpan rangePausedTime = SlaPausedTimes.CalculatePausedTime(loginUser,
                                                                                  organization,
                                                                                  slaTrigger,
                                                                                  slaPausedTime.PausedOnUtc,
                                                                                  (DateTime)slaPausedTime.ResumedOnUtc,
                                                                                  businessHours,
                                                                                  daysToPause,
                                                                                  holidays,
                                                                                  logs);
                    totalPausedTime = totalPausedTime.Add(rangePausedTime);

                    //return the results to stored them in the db.
                    businessPausedTimes.Add(slaPausedTime.Id, rangePausedTime.TotalSeconds);
                }
                else if (hasBeenCalculated && !overwritePrevious)
                {
                    TimeSpan previouslyCalculatedPausedTime = TimeSpan.FromSeconds((int)slaPausedTime.BusinessPausedTime);
                    totalPausedTime = totalPausedTime.Add(previouslyCalculatedPausedTime);
                }
            }

            return(totalPausedTime);
        }
Beispiel #15
0
 public int?AddBusinessHours(BusinessHours businessHours)
 {
     using (var dbContextTransaction = _context.Database.BeginTransaction())
     {
         try
         {
             _context.BusinessHours.Add(businessHours);
             _context.SaveChanges();
             dbContextTransaction.Commit();
             return(1);
         }
         catch (Exception)
         {
             dbContextTransaction.Rollback();
             return(0);
         }
     }
 }
Beispiel #16
0
        private static IEnumerable <TimeSpan> GetAllPossibleReservationStartingTimes(BusinessHours businessHours)
        {
            var      allPossibleReservationStartingTimes = new List <TimeSpan>();
            TimeSpan startingReservationTime             = businessHours.OpeningTime;
            TimeSpan lastReservationTime = businessHours.ClosingTime;

            if (businessHours.OpeningTime > businessHours.ClosingTime)
            {
                lastReservationTime = businessHours.ClosingTime + TimeSpan.FromDays(1);
            }

            lastReservationTime -= new TimeSpan(1, 30, 0);

            while (startingReservationTime <= lastReservationTime)
            {
                allPossibleReservationStartingTimes.Add(startingReservationTime);
                startingReservationTime = startingReservationTime.Add(new TimeSpan(0, 30, 0));
            }

            return(allPossibleReservationStartingTimes);
        }
        private void Setup()
        {
            var pois = new List <PointOfInterest>();

            var user = new User()
            {
                Id          = "1",
                UserName    = "******",
                Email       = "*****@*****.**",
                DisplayName = "Administrator"
            };

            var b = new BusinessHours {
                FromHour = new TimeSpan(9, 0, 0), ToHour = new TimeSpan(17, 59, 59)
            };

            var p = new PointOfInterest(location, "Teste 1", b, 1, user);

            p.Id = 1;
            p.Approve();

            pois.Add(p);
            pois.Add(new PointOfInterest(location, "Teste 2", b, 1, user)
            {
                Id = 2
            });

            p    = new PointOfInterest(location, "Teste 3", b, 1, user);
            p.Id = 3;
            p.Approve();
            pois.Add(p);

            pois.Add(new PointOfInterest(location, "Teste 4", b, 1, user)
            {
                Id = 4
            });

            this.pointsOfInterest = pois.AsQueryable();
        }
Beispiel #18
0
        /*
         * Method to check if a venue is available for a game during a certain timeframe
         */
        public bool IsVenueAvailable(List <BusinessHours> venueHours, DateTime startDateTime, DateTime endDateTime)
        {
            // If no business hours then venue has no hours and is therefore not available
            if (venueHours == null)
            {
                return(false);
            }

            // Only checking start date because games should not span over a day
            DayOfWeek     startDate     = startDateTime.DayOfWeek;
            BusinessHours venueOpenDate = venueHours.FirstOrDefault(x => x.DayOfWeek == (int)startDate);

            // Venue is open that date, check timeframes
            if (venueOpenDate != null)
            {
                TimeSpan startTime = startDateTime.TimeOfDay;
                TimeSpan endTime   = endDateTime.TimeOfDay;

                // Change midnight to 11:59 PM for accurate time comparisons
                if (venueOpenDate.CloseTime == new TimeSpan(00, 00, 00))
                {
                    venueOpenDate.CloseTime = new TimeSpan(23, 59, 00);
                }

                // Ensure both start and end times are within range
                if (startTime > venueOpenDate.OpenTime && startTime < venueOpenDate.CloseTime)
                {
                    if (endTime > venueOpenDate.OpenTime && endTime < venueOpenDate.CloseTime)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #19
0
        public static DateTime?CalculateSLAWarning(DateTime ViolationDate,
                                                   BusinessHours businessHours,
                                                   bool noBusinessHours,
                                                   int minutes,
                                                   int slaWarningTime,
                                                   List <DateTime> daysToPause,
                                                   CalendarEvents holidays)
        {
            DateTime?slaDayStart     = businessHours.DayStartUtc;
            DateTime?slaDayEnd       = businessHours.DayEndUtc;
            int      slaBusinessDays = businessHours.BusinessDays;
            DateTime?ExpireDate      = new DateTime();
            int      adjustedMinutes = 0;

            if (slaDayStart == null || slaDayEnd == null || slaBusinessDays < 1 || minutes < 1)
            {
                ExpireDate = null;
            }
            else if (noBusinessHours)
            {
                ExpireDate = ViolationDate.AddMinutes(-slaWarningTime);
            }
            else
            {
                //The Violation needs to be calculated first, which means the start date is already valid.
                int startOfDayMinutes = slaDayStart.Value.Minute + (slaDayStart.Value.Hour * 60);

                //When converted the input to UTC the end time might be less than the start time. E.g. central 8 to 22, is stored as utc 14 to 4
                if (businessHours.DayEndUtc.Hour < businessHours.DayStartUtc.Hour && businessHours.DayEndUtc.Day > businessHours.DayStartUtc.Day)
                {
                    adjustedMinutes   = slaDayStart.Value.Minute + slaDayStart.Value.Hour * 60;
                    slaDayStart       = slaDayStart.Value.AddMinutes(-adjustedMinutes);
                    slaDayEnd         = slaDayEnd.Value.AddMinutes(-adjustedMinutes);
                    ViolationDate     = ViolationDate.AddMinutes(-adjustedMinutes);
                    startOfDayMinutes = slaDayStart.Value.Minute + (slaDayStart.Value.Hour * 60);
                }

                int slaDays    = (slaWarningTime / 60) / 24;
                int slaHours   = (slaWarningTime - (slaDays * 24 * 60)) / 60;
                int slaMinutes = slaWarningTime - (slaDays * 24 * 60) - (slaHours * 60);
                ExpireDate = ViolationDate;

                //1) process days
                while (slaDays > 0)
                {
                    ExpireDate = ExpireDate.Value.AddDays(-1);

                    if (IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                    {
                        slaDays--;
                    }
                }

                //2) process hours
                while (slaHours > 0)
                {
                    ExpireDate = ExpireDate.Value.AddHours(-1);

                    if (ExpireDate.Value.Hour < slaDayStart.Value.Hour)
                    {
                        ExpireDate = GetPreviousBusinessDay(ExpireDate.Value, slaBusinessDays);
                        TimeSpan difference = (new DateTime(ExpireDate.Value.Year, ExpireDate.Value.Month, ExpireDate.Value.Day, slaDayStart.Value.Hour, slaDayStart.Value.Minute, 0)) - (DateTime)ExpireDate;
                        ExpireDate = new DateTime(ExpireDate.Value.Year, ExpireDate.Value.Month, ExpireDate.Value.Day, slaDayEnd.Value.Hour, slaDayEnd.Value.Minute, 0);
                        ExpireDate = ExpireDate.Value.AddHours(-1 * difference.Hours).AddMinutes(-1 * difference.Minutes).AddSeconds(-1 * difference.Seconds);
                    }

                    if (IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                    {
                        slaHours--;
                    }
                }

                //3) process minutes
                while (slaMinutes > 0)
                {
                    DateTime control = ExpireDate.Value;
                    ExpireDate = ExpireDate.Value.AddMinutes(-1);

                    if (!ExpireDate.Value.Date.Equals(control.Date))
                    {
                        ExpireDate = new DateTime(ExpireDate.Value.Year, ExpireDate.Value.Month, ExpireDate.Value.Day, slaDayEnd.Value.Hour, slaDayEnd.Value.Minute, 0);
                        ExpireDate = ExpireDate.Value.AddMinutes(-1);

                        if (!IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                        {
                            ExpireDate = GetPreviousBusinessDay(ExpireDate.Value, slaBusinessDays);
                        }
                    }

                    if (ExpireDate.Value.Hour < slaDayStart.Value.Hour)
                    {
                        ExpireDate = GetPreviousBusinessDay(ExpireDate.Value, slaBusinessDays);
                        TimeSpan difference = (new DateTime(ExpireDate.Value.Year, ExpireDate.Value.Month, ExpireDate.Value.Day, slaDayStart.Value.Hour, slaDayStart.Value.Minute, 0)) - (DateTime)ExpireDate;
                        ExpireDate = new DateTime(ExpireDate.Value.Year, ExpireDate.Value.Month, ExpireDate.Value.Day, slaDayEnd.Value.Hour, slaDayEnd.Value.Minute, 0);
                        ExpireDate = ExpireDate.Value.AddMinutes(-1 * difference.Minutes).AddSeconds(-1 * difference.Seconds);
                    }

                    if (IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                    {
                        slaMinutes--;
                    }
                }

                //And only if the ExpireDate falls outside business hours, due to start > end business hours because of the UTC
                if (businessHours.DayEndUtc.Hour < businessHours.DayStartUtc.Hour && businessHours.DayEndUtc.Day > businessHours.DayStartUtc.Day &&
                    ExpireDate.Value.Hour < businessHours.DayStartUtc.Hour)
                {
                    ExpireDate = ExpireDate.Value.AddMinutes(adjustedMinutes);
                }

                //last check to make sure it didn't fall into a Holiday, if so move onto the next valid day
                while (!IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                {
                    ExpireDate = GetPreviousBusinessDay(ExpireDate.Value, slaBusinessDays);
                }
            }

            return(ExpireDate);
        }
        public ActionResult Add(
            BusinessHoursModel model,
            List <string> morningHour,
            List <string> morningPeriod,
            List <string> eveningHour,
            List <string> eveningPeriod)
        {
            if (model.SelectedBusinessHoursType == "1")
            {
                BusinessHours businessHours = new BusinessHours()
                {
                    BusinessHoursId   = 0,
                    Description       = model.Description,
                    HelpdeskHoursType = Convert.ToInt32(model.SelectedBusinessHoursType),
                    Name = model.Name
                };

                _businessHours.AddBusinessHours(businessHours);

                TempData["BusinessHoursMessage"] = "BusinessHours Saved Successfully";
            }
            else
            {
                if (model.SelectedDays == null)
                {
                    ModelState.AddModelError("", "Please SelectedDays");
                }
                else
                {
                    BusinessHours businessHours = new BusinessHours
                    {
                        BusinessHoursId   = 0,
                        Description       = model.Description,
                        HelpdeskHoursType = Convert.ToInt32(model.SelectedBusinessHoursType),
                        Name = model.Name
                    };

                    List <BusinessHoursDetails> listBusinessHoursDetails = new List <BusinessHoursDetails>();

                    for (int i = 0; i < model.SelectedDays.Count(); i++)
                    {
                        var currentMorningHour   = morningHour[i];
                        var currentMorningPeriod = morningPeriod[i];
                        var currentEveningHour   = eveningHour[i];
                        var currentEveningPeriod = eveningPeriod[i];
                        var currentday           = model.SelectedDays[i];

                        var starthours = DateTime.Parse($"{currentMorningHour + ":00" + " " + currentMorningPeriod.ToUpper()}").ToString("HH:mm:ss", CultureInfo.InvariantCulture);
                        var endhours   = DateTime.Parse($"{currentEveningHour + ":00" + " " + currentEveningPeriod.ToUpper()}").ToString("HH:mm:ss", CultureInfo.InvariantCulture);


                        BusinessHoursDetails businessHoursDetails = new BusinessHoursDetails()
                        {
                            BusinessHoursId        = 0,
                            BusinessHoursDetailsId = 0,
                            CreateDate             = DateTime.Now,
                            Day            = currentday,
                            MorningTime    = $"{currentMorningHour + ":00" + " " + currentMorningPeriod.ToUpper()}",
                            EveningTime    = $"{currentEveningHour + ":00" + " " + currentEveningPeriod.ToUpper()}",
                            MorningPeriods = currentMorningPeriod,
                            EveningPeriods = currentEveningPeriod,
                            StartTime      = starthours,
                            CloseTime      = endhours
                        };

                        listBusinessHoursDetails.Add(businessHoursDetails);
                    }

                    _businessHours.AddBusinessHours(businessHours, listBusinessHoursDetails);
                    TempData["BusinessHoursMessage"] = "BusinessHours Saved Successfully";

                    return(RedirectToAction("Add", "BusinessHours"));
                }
            }

            model.ListofDays              = Dayslist();
            model.ListofHour              = Hourlist();
            model.ListofPeriod            = Periodslist();
            model.SelectedDays            = new List <string>();
            model.ListofBusinessHoursType = _businessHours.ListofBusinessHoursType();
            return(View(model));
        }
Beispiel #21
0
 /*
  * Given Business Hours, add to database
  */
 public void AddBusinessHour(BusinessHours hour)
 {
     _businessHoursRepository.AddBusinessHours(hour);
 }
Beispiel #22
0
        public static DateTime?CalculateSLA(DateTime DateCreated,
                                            BusinessHours businessHours,
                                            SlaTrigger slaTrigger,
                                            int minutes,
                                            TimeSpan pausedTimeSpan,
                                            List <DateTime> daysToPause,
                                            CalendarEvents holidays)
        {
            bool     slaUseBusinessHours = slaTrigger.UseBusinessHours;
            DateTime?slaDayStart         = businessHours.DayStartUtc;
            DateTime?slaDayEnd           = businessHours.DayEndUtc;
            int      slaBusinessDays     = businessHours.BusinessDays;
            DateTime?ExpireDate          = new DateTime();
            int      adjustedMinutes     = 0;

            if ((slaUseBusinessHours && (slaDayStart == null || slaDayEnd == null || slaBusinessDays < 1)) ||
                minutes < 1)
            {
                ExpireDate = null;
            }
            else
            {
                if ((slaUseBusinessHours && slaBusinessDays == 0) ||
                    (!slaUseBusinessHours && DateTime.Compare(slaDayStart.Value, slaDayEnd.Value) == 0 && slaBusinessDays == 127) ||
                    slaTrigger.NoBusinessHours)    //127 means all days are selected.
                {
                    ExpireDate = DateCreated.AddMinutes(minutes);
                }
                else
                {
                    int startOfDayMinutes         = slaDayStart.Value.Minute + (slaDayStart.Value.Hour * 60);
                    int endOfDayMinutes           = slaDayEnd.Value.Minute + (slaDayEnd.Value.Hour * 60);
                    int currentMinuteInTheProcess = DateCreated.Minute + (DateCreated.Hour * 60);
                    int minutesInOneDay           = (24 * 60);

                    //When converted the input to UTC the end time might be less than the start time. E.g. central 8 to 22, is stored as utc 14 to 4
                    if (businessHours.DayEndUtc.Hour < businessHours.DayStartUtc.Hour && businessHours.DayEndUtc.Day > businessHours.DayStartUtc.Day)
                    {
                        adjustedMinutes           = slaDayStart.Value.Minute + slaDayStart.Value.Hour * 60;
                        slaDayStart               = slaDayStart.Value.AddMinutes(-adjustedMinutes);
                        slaDayEnd                 = slaDayEnd.Value.AddMinutes(-adjustedMinutes);
                        DateCreated               = DateCreated.AddMinutes(-adjustedMinutes);
                        startOfDayMinutes         = slaDayStart.Value.Minute + (slaDayStart.Value.Hour * 60);
                        endOfDayMinutes           = slaDayEnd.Value.Minute + (slaDayEnd.Value.Hour * 60);
                        currentMinuteInTheProcess = (DateCreated.Minute + (DateCreated.Hour * 60));
                    }

                    //Make sure endOfDayMinutes is greater than startOfDayMinutes
                    if (startOfDayMinutes >= endOfDayMinutes)
                    {
                        //Add 1 day worth of minutes
                        endOfDayMinutes = endOfDayMinutes + minutesInOneDay;
                    }

                    int minutesInBusinessDay = endOfDayMinutes - startOfDayMinutes;

                    //Make sure the start time falls within business hours
                    if (currentMinuteInTheProcess > endOfDayMinutes)
                    {
                        //Reset the time to start of bussiness day AND add 1 day
                        DateCreated = DateCreated.Date.AddDays(1).Add(slaDayStart.Value.TimeOfDay);
                    }
                    else if (currentMinuteInTheProcess < startOfDayMinutes)
                    {
                        DateCreated = DateCreated.Date.Add(slaDayStart.Value.TimeOfDay);
                    }

                    //Repeat until we find the first business day, non-pause day, non-holiday
                    while (!IsValidDay(DateCreated, slaBusinessDays, daysToPause, holidays))
                    {
                        DateCreated = DateCreated.AddDays(1);
                        //If this happened then we need to set it with the start of day hour
                        DateCreated = new DateTime(DateCreated.Year, DateCreated.Month, DateCreated.Day, slaDayStart.Value.Hour, slaDayStart.Value.Minute, 0);
                    }

                    //DateCreated now contains a valid date to start SLA with business days
                    currentMinuteInTheProcess = DateCreated.Minute + (DateCreated.Hour * 60);

                    int slaDays    = (minutes / 60) / 24;
                    int slaHours   = (minutes - (slaDays * 24 * 60)) / 60;
                    int slaMinutes = minutes - (slaDays * 24 * 60) - (slaHours * 60);

                    ExpireDate = DateCreated;
                    //1) process days
                    while (slaDays > 0)
                    {
                        ExpireDate = ExpireDate.Value.AddDays(1);

                        if (IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                        {
                            slaDays--;
                        }
                    }

                    //2) process hours
                    while (slaHours > 0)
                    {
                        ExpireDate = ExpireDate.Value.AddHours(1);

                        if (ExpireDate.Value.Hour > slaDayEnd.Value.Hour || (ExpireDate.Value.Hour == slaDayEnd.Value.Hour && ExpireDate.Value.Minute > slaDayEnd.Value.Minute))
                        {
                            ExpireDate = GetNextBusinessDay(ExpireDate.Value, slaBusinessDays);
                            int minuteOffset = ExpireDate.Value.Minute - slaDayEnd.Value.Minute;
                            ExpireDate = new DateTime(ExpireDate.Value.Year, ExpireDate.Value.Month, ExpireDate.Value.Day, slaDayStart.Value.Hour, slaDayStart.Value.Minute, 0);
                            ExpireDate = ExpireDate.Value.AddMinutes(minuteOffset);
                        }

                        if (IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                        {
                            slaHours--;
                        }
                        else
                        {
                            ExpireDate = GetNextBusinessDay(ExpireDate.Value, slaBusinessDays);
                            ExpireDate = ExpireDate.Value.AddHours(-1);
                        }
                    }

                    //3) process minutes
                    while (slaMinutes > 0)
                    {
                        ExpireDate = ExpireDate.Value.AddMinutes(1);

                        if (ExpireDate.Value.Hour == slaDayEnd.Value.Hour && ExpireDate.Value.Minute > slaDayEnd.Value.Minute)
                        {
                            ExpireDate = GetNextBusinessDay(ExpireDate.Value, slaBusinessDays);
                            ExpireDate = new DateTime(ExpireDate.Value.Year, ExpireDate.Value.Month, ExpireDate.Value.Day, slaDayStart.Value.Hour, slaDayStart.Value.Minute, 0);
                        }

                        if (IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                        {
                            slaMinutes--;
                        }
                        else
                        {
                            ExpireDate = GetNextBusinessDay(ExpireDate.Value, slaBusinessDays);
                            ExpireDate = ExpireDate.Value.AddMinutes(-1);
                        }
                    }
                }

                ExpireDate = AddPausedTime((DateTime)ExpireDate, pausedTimeSpan, slaBusinessDays, slaDayStart, slaDayEnd, slaUseBusinessHours);

                if (businessHours.DayEndUtc.Hour < businessHours.DayStartUtc.Hour && businessHours.DayEndUtc.Day > businessHours.DayStartUtc.Day)
                {
                    ExpireDate = ExpireDate.Value.AddMinutes(adjustedMinutes);
                }

                //last check to make sure it didn't fall into a Holiday, if so move onto the next valid day
                while (!IsValidDay(ExpireDate.Value, slaBusinessDays, daysToPause, holidays))
                {
                    ExpireDate = GetNextBusinessDay(ExpireDate.Value, slaBusinessDays);
                }
            }

            return(ExpireDate);
        }
Beispiel #23
0
 public void Edit(BusinessHours businessHours)
 {
     _context.Entry(businessHours).State = EntityState.Modified;
     _context.SaveChanges();
 }
Beispiel #24
0
 /*
  * Given Business Hours, update those BusinessHours in database
  */
 public void UpdateBusinessHours(BusinessHours hours)
 {
     _businessHoursRepository.Edit(hours);
 }
Beispiel #25
0
 /*
  * Given Business Hours, delete from database
  */
 public void DeleteBusinessHours(BusinessHours hours)
 {
     _businessHoursRepository.Delete(hours);
 }
Beispiel #26
0
 public void Init()
 {
     instance = new BusinessHours();
 }
Beispiel #27
0
        /**
         * Add or update venue details in database
         */
        private void UpdateVenueDetails()
        {
            // Get all venues
            List <Venue> venues = _venueRepository.GetAllVenues();

            // Get only venues that don't have details
            List <Venue> venuesWithoutDetails = venues.Where(v => v.Address1 == null).ToList();

            foreach (var venue in venuesWithoutDetails)
            {
                // Venue owners have ability to manually update their venues, do not auto-update
                if (VenueHasOwner(venue))
                {
                    continue;
                }

                // Get Place details from Google API using GooglePlaceId
                PlaceDetailsResponse venueDetails = _placesApi.GetPlaceDetailsById(venue.GooglePlaceId);

                // Map response data to database model properties
                venue.Phone = venueDetails.Result.FormattedPhoneNumber;
                string streetAddress = null;
                foreach (var addressComponent in venueDetails.Result.AddressComponents)
                {
                    // Map Address from response to database model
                    var type = addressComponent.Types.FirstOrDefault();
                    switch (type)
                    {
                    case "street_number":
                        streetAddress += addressComponent.ShortName + " ";
                        break;

                    case "route":
                        streetAddress += addressComponent.ShortName;
                        break;

                    case "locality":
                        venue.City = addressComponent.ShortName;
                        break;

                    case "administrative_area_level_1":
                        venue.State = addressComponent.ShortName;
                        break;

                    case "postal_code":
                        venue.ZipCode = addressComponent.ShortName;
                        break;

                    default:
                        continue;
                    }

                    venue.Address1 = streetAddress;
                }

                // Update Venue entity
                _venueRepository.Edit(venue);

                // Map OpeningHours API response to BusinessHours entity
                if (venueDetails.Result.OpeningHours != null)
                {
                    // Initialize new BusinessHours entity using VenueID as foreign key
                    BusinessHours hours = new BusinessHours {
                        VenueId = venue.VenueId
                    };

                    foreach (var period in venueDetails.Result.OpeningHours.Periods)
                    {
                        hours.DayOfWeek = period.Open.Day;

                        string openTime = period.Open?.Time.Insert(2, ":");
                        if (!string.IsNullOrEmpty(openTime))
                        {
                            hours.OpenTime = DateTime.Parse(openTime).TimeOfDay;
                        }

                        string closeTime = period.Close?.Time.Insert(2, ":");
                        if (!string.IsNullOrEmpty(closeTime))
                        {
                            hours.CloseTime = DateTime.Parse(closeTime).TimeOfDay;
                        }

                        // Add BusinessHours entity
                        _businessHoursRepository.AddBusinessHours(hours);
                    }
                }

                // Map Review API response to Review database entity
                if (venueDetails.Result.Reviews != null)
                {
                    foreach (var review in venueDetails.Result.Reviews)
                    {
                        DateTime timestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

                        Review reviewEntity = new Review
                        {
                            IsGoogleReview = true,
                            GoogleAuthor   = review.AuthorName,
                            VenueId        = venue.VenueId,
                            Comments       = review.Text,
                            Rating         = review.Rating,

                            Timestamp = timestamp.AddSeconds(review.Time).ToLocalTime()
                        };

                        _reviewRepository.AddReview(reviewEntity);
                    }
                }

                // Map Location API response to Location database entity
                if (venueDetails.Result.Geometry != null)
                {
                    Location locationEntity = new Location
                    {
                        Latitude =
                            venueDetails.Result.Geometry.GeometryLocation.Latitude.ToString(CultureInfo.InvariantCulture),
                        Longitude =
                            venueDetails.Result.Geometry.GeometryLocation.Longitude.ToString(CultureInfo.InvariantCulture),
                        VenueId = venue.VenueId
                    };

                    // Add Location entity
                    _locationRepository.AddLocation(locationEntity);
                }
            }
        }
Beispiel #28
0
        public ActionResult EditVenue(int id)
        {
            //Populate states dropdown
            ViewBag.States = PopulateStatesDropdown();

            //Get the current logged in user
            string currUser = User.Identity.GetUserName();

            //If the current user is not the venue owner then redirect them to details of venue
            if (!_venueOwnerService.IsVenueOwner(currUser))
            {
                ViewBag.States = PopulateStatesDropdown();
                return(RedirectToAction("Details", new { id = id }));
            }

            //Find the venues with the ID
            Venue venue = _venueService.GetVenueById(id);

            //Gotta get business hours for the venues
            List <BusinessHours> businessHours = _venueService.GetVenueBusinessHours(id);

            //create a shell for business hours with complete set of day of weeks
            List <BusinessHours> shell = new List <BusinessHours>();

            for (int i = 0; i < 7; i++)
            {
                shell.Add(new BusinessHours()
                {
                    DayOfWeek = i,
                    VenueId   = id
                });
            }

            //If there is an existing hours for the venue, match it with the day of week in the shell and insert it
            foreach (var hours in businessHours)
            {
                BusinessHours matchHours = shell.Find(x => x.DayOfWeek == hours.DayOfWeek);
                matchHours.BusinessHoursId = hours.BusinessHoursId;
                matchHours.CloseTime       = hours.CloseTime;
                matchHours.OpenTime        = hours.OpenTime;
            }

            //Creating a Business hour VM for the view model passing back to the venue view
            List <BusinessHoursViewModel> businessHoursViewModels = new List <BusinessHoursViewModel>();

            foreach (var hours in shell)
            {
                //initializing the opening and closing string
                string openTimeString    = "";
                string closingTimeString = "";

                //if the hours are not null then pass it in
                if (hours.CloseTime != TimeSpan.Zero || hours.OpenTime != TimeSpan.Zero)
                {
                    openTimeString    = hours.OpenTime.ToString();
                    closingTimeString = hours.CloseTime.ToString();
                }

                //Create a new Business hours view model with it, either if it has a data or an empty string
                BusinessHoursViewModel hoursViewModel = new BusinessHoursViewModel()
                {
                    DayOfWeek = Enum.Parse(typeof(DayOfWeek), hours.DayOfWeek.ToString()).ToString(),
                    CloseTime = closingTimeString,
                    OpenTime  = openTimeString
                };

                //Add the business hours
                businessHoursViewModels.Add(hoursViewModel);
            }

            //Create the View Model for the Edit View
            VenueViewModel model = new VenueViewModel
            {
                VenueId       = venue.VenueId,
                Name          = venue.Name,
                Address1      = venue.Address1,
                Address2      = venue.Address2,
                City          = venue.City,
                Phone         = venue.Phone,
                State         = venue.State,
                ZipCode       = venue.ZipCode,
                BusinessHours = businessHoursViewModels
            };


            return(View(model));
        }
Beispiel #29
0
        public ActionResult EditVenue(VenueViewModel model)
        {
            //Populate states dropdown
            ViewBag.States = PopulateStatesDropdown();

            //Editing the venue details
            Venue existingVenue = _venueService.GetVenueById(model.VenueId);

            existingVenue.Address1    = model.Address1;
            existingVenue.Address2    = model.Address2;
            existingVenue.City        = model.City;
            existingVenue.DateUpdated = DateTime.Now;
            existingVenue.Name        = model.Name;
            existingVenue.Phone       = model.Phone;
            existingVenue.State       = model.State;
            existingVenue.ZipCode     = model.ZipCode;

            //find the current hours of the venue using the venueId
            List <BusinessHours> existingHours = _venueService.GetVenueBusinessHours(model.VenueId);

            TimeSpan beginTimeSpan = TimeSpan.Zero;
            TimeSpan endTimeSpan   = TimeSpan.Zero;

            //for each hours in the view modeling hours - runs 7 times since the days of weeks are not null
            foreach (var hours in model.BusinessHours)
            {
                //convert the string day of week to numbers to be able to pass it back into the dB
                DayOfWeek convertDayOfWeek = (DayOfWeek)(Enum.Parse(typeof(DayOfWeek), hours.DayOfWeek));

                //Match the day of week with the existing
                BusinessHours checkHours = existingHours.Find(x => x.DayOfWeek == (int)convertDayOfWeek);

                //Check if only one field is filled and the other isn't
                if (hours.OpenTime != null && hours.CloseTime == null)
                {
                    ViewBag.States = PopulateStatesDropdown();
                    ViewData.ModelState.AddModelError("BothTimeFilled", "Please fill out both Opening and Ending Time for the certain day");
                    return(View(model));
                }
                if (hours.OpenTime == null && hours.CloseTime != null)
                {
                    ViewBag.States = PopulateStatesDropdown();
                    ViewData.ModelState.AddModelError("BothTimeFilled", "Please fill out both Opening and Ending Time for the certain day");
                    return(View(model));
                }

                //If the Open Time and the Closing Time are not null, there was time entered into it
                if (hours.OpenTime != null && hours.CloseTime != null)
                {
                    //Checking if it is a valid format, if so assign it to the TimeSpan variable initialized above
                    bool checkOpenTime  = TimeSpan.TryParse(hours.OpenTime, out beginTimeSpan);
                    bool checkCloseTime = TimeSpan.TryParse(hours.CloseTime, out endTimeSpan);

                    if (!checkCloseTime && !checkOpenTime)
                    {
                        ViewBag.States = PopulateStatesDropdown();
                        ViewData.ModelState.AddModelError("ValidTime", "The time must be between 00:00 - 23:00");
                        return(View(model));
                    }


                    //checking if opening time and closing time is valid
                    if (beginTimeSpan >= endTimeSpan)
                    {
                        ViewBag.States = PopulateStatesDropdown();
                        ViewData.ModelState.AddModelError("TimeRange", "The Opening Time cannot be after or equal to the Closing Time");
                        return(View(model));
                    }

                    //Case: 1: Adding new Business Hours - If checkHours equals null, then there was no match so time to add in a new business hour
                    if (checkHours == null)
                    {
                        _venueService.AddBusinessHour(new BusinessHours()
                        {
                            VenueId   = model.VenueId,
                            CloseTime = TimeSpan.Parse(hours.CloseTime),
                            OpenTime  = TimeSpan.Parse(hours.OpenTime),
                            DayOfWeek = (int)convertDayOfWeek
                        });
                    }
                    //Case: 2 Modify Business Hours - if checkHours is not null there was a match
                    else
                    {
                        checkHours.CloseTime = TimeSpan.Parse(hours.CloseTime);
                        checkHours.OpenTime  = TimeSpan.Parse(hours.OpenTime);

                        _venueService.UpdateBusinessHours(checkHours);
                    }
                }

                //Case:3 Deleting Business Hours - user removes the business hours from the venue
                if (checkHours != null && (hours.OpenTime == null && hours.CloseTime == null))
                {
                    _venueService.DeleteBusinessHours(checkHours);
                }
            }

            //Edit the generic information of the venue excluding the business hours
            _venueService.EditVenue(existingVenue);



            return(RedirectToAction("Details", new { id = model.VenueId }));
        }