protected OpeningTimes GetDayOpeningTimes(string day, string str) { var openingTimes = new OpeningTimes(day); if (string.IsNullOrEmpty(str)) { return(openingTimes); } try { var hours = new List <StartEndTime>(); var openingHoursArray = JsonConvert.DeserializeObject <JArray>(str);//.FirstOrDefault(); foreach (var openingHoursVal in openingHoursArray) { var title = openingHoursVal.Value <string>("title"); var startTime = openingHoursVal.Value <DateTime?>("startTime"); var endTime = openingHoursVal.Value <DateTime?>("endTime"); if (startTime != null || endTime != null) { var startEndTime = new StartEndTime { Title = title }; if (startTime != null) { startEndTime.StartTime = ((DateTime)startTime).ToString("HH:mm:ss"); } if (endTime != null) { startEndTime.EndTime = ((DateTime)endTime).ToString("HH:mm:ss"); } hours.Add(startEndTime); } } openingTimes.Hours = hours; } catch (Exception) { return(openingTimes); } return(openingTimes); }
private string OpenTime(DateTime now, OpeningTimes times, out bool isOpen) { isOpen = false; if (times == null && !times.Hours.Any()) { return(null); } foreach (var hour in times.Hours) { if (!string.IsNullOrEmpty(hour.StartTime) && !string.IsNullOrEmpty(hour.EndTime)) { int startHour, startMinute; var splitStart = hour.StartTime.Split(':'); int.TryParse(splitStart[0], out startHour); int.TryParse(splitStart[1], out startMinute); var start = new DateTime(now.Year, now.Month, now.Day, startHour, startMinute, 0); if (start > now) { isOpen = false; return(hour.StartTime); } int endHour, endMinute; var splitEnd = hour.EndTime.Split(':'); int.TryParse(splitEnd[0], out endHour); int.TryParse(splitEnd[1], out endMinute); var end = new DateTime(now.Year, now.Month, now.Day, endHour, endMinute, 0); if (end > now) { isOpen = true; return(hour.StartTime); } } } return(null); }
private static void WorkOutNextOpen(LocationViewModel model, OpeningTimes opening, DateTime ukNow) { if (opening.Scheduled && opening.OpensAtTime.HasValue && opening.OpensAtTime > ukNow && opening.OpensAtTime < model.NextOpen) { model.NextOpen = opening.OpensAtTime.Value; } if (opening.Scheduled && opening.OpensAgainAtTime.HasValue && opening.OpensAgainAtTime > ukNow && opening.OpensAgainAtTime < model.NextOpen) { model.NextOpen = opening.OpensAgainAtTime.Value; } // If it's open this day, and we've no better offer, it'll be open again this time next week if (opening.Scheduled && opening.OpensAtTime.HasValue) { var sameTimeNextWeek = opening.OpensAtTime.Value.AddDays(7); if (model.NextOpen > sameTimeNextWeek) { model.NextOpen = sameTimeNextWeek; } } }
private static void WorkOutOpenUntil(LocationViewModel model, DateTime ukNow, OpeningTimes opening) { var today = (ukNow.DayOfWeek.ToString().Substring(0, 2).ToUpperInvariant() == opening.Day.Substring(0, 2).ToUpperInvariant()); var now = ukNow.TimeOfDay; var open1 = (opening.OpensAtTime.HasValue && opening.ClosesAtTime.HasValue && now >= opening.OpensAtTime.Value.TimeOfDay && now <= opening.ClosesAtTime.Value.TimeOfDay); var open2 = (opening.OpensAgainAtTime.HasValue && opening.ClosesAgainAtTime.HasValue && now >= opening.OpensAgainAtTime.Value.TimeOfDay && now <= opening.ClosesAgainAtTime.Value.TimeOfDay); var open = today && opening.Scheduled && (open1 || open2); if (open && open1) { model.OpenUntil = opening.ClosesAtTime; } if (open && open2) { model.OpenUntil = opening.ClosesAgainAtTime; } }
//Init used data public DummyProject3_BackendContext() { // Create objects Category category1 = new Category { CategoryId = 0, Name = "Afvallen" }; Challenge challenge1 = new Challenge { ChallengeId = 0, ChallengeImage = "Image url", Description = "Loop 1500 meter", Title = "First run" }; Challenge challenge2 = new Challenge { ChallengeId = 1, ChallengeImage = "Image url", Description = "Loop 2000 meter", Title = "Second run" }; Company company1 = new Company { CompanyId = 0, City = "Wetteren", Contract = new DateTime(2020, 05, 15), Country = "België", HouseNumber = 3, Mail = "*****@*****.**", Name = "Xenox", Phone = "0474139526", PostalCode = 9230, Site = "www.google.com", Street = "Kalkensteenweg" }; User user1 = new User { UserId = 0, Phone = "0473139526", Contract = new DateTime(2020, 05, 15), Email = "*****@*****.**", ExperiencePoints = 0, FamilyName = "Grillaert", FirstName = "Ruben" }; User user2 = new User { UserId = 1, Phone = "0412345678", Contract = new DateTime(2020, 05, 15), Email = "*****@*****.**", ExperiencePoints = 0, FamilyName = "Boel", FirstName = "Arno" }; Therapist therapist1 = new Therapist { TherapistId = 0, City = "stad", Email = "*****@*****.**", FirstName = "Thor", HouseNumber = 2, LastName = "Krets", PhoneNumber = "093661686", PostalCode = 9000, Street = "straat", Website = "www.test.be" }; OpeningTimes openingTimes1 = new OpeningTimes { OpeningTimesId = 0, Interval = "09:00 - 18:30" }; OpeningTimes openingTimes2 = new OpeningTimes { OpeningTimesId = 1, Interval = "09:00 - 18:30" }; TherapistType therapistType1 = new TherapistType { TherapistTypeId = 0, Type = "therapisttype", }; // Create many to many objects ChallengeUser challengeUser1 = new ChallengeUser { Challenge = challenge1, ChallengeId = challenge1.ChallengeId, ChallengeUserId = 0, User = user1, UserId = user1.UserId }; ChallengeUser challengeUser2 = new ChallengeUser { Challenge = challenge2, ChallengeId = challenge2.ChallengeId, ChallengeUserId = 1, User = user1, UserId = user1.UserId }; TherapistUser therapistUser1 = new TherapistUser { TherapistUserId = 0, Therapist = therapist1, TherapistId = therapist1.TherapistId, User = user1, UserId = user1.UserId }; TherapistUser therapistUser2 = new TherapistUser { TherapistUserId = 1, Therapist = therapist1, TherapistId = therapist1.TherapistId, User = user2, UserId = user2.UserId }; // Set connections between objects challenge1.Category = category1; challenge2.Category = category1; company1.CompanyMembers = new List <User>() { user1, user2 }; therapist1.OpeningTimes = new List <OpeningTimes>() { openingTimes1 }; therapist1.TherapistType = therapistType1; therapistType1.Categories = new List <Category>() { category1 }; user1.Categories = new List <CategoryUser>() { new CategoryUser() { CategoryId = category1.CategoryId, Category = category1, User = user1, UserId = user1.UserId } }; user2.Categories = new List <CategoryUser>() { new CategoryUser() { CategoryId = category1.CategoryId, Category = category1, User = user2, UserId = user2.UserId } }; user1.Challenges = new List <ChallengeUser>() { challengeUser1, challengeUser2 }; user2.Challenges = new List <ChallengeUser>(); user1.Company = company1; user2.Company = company1; user1.Therapists = new List <TherapistUser>() { therapistUser1 }; user2.Therapists = new List <TherapistUser>() { therapistUser2 }; // Init properties Category = category1; Categories = new[] { category1 }; Companies = new[] { company1 }; Challenges = new[] { challenge1, challenge2 }; Therapists = new[] { therapist1 }; Users = new[] { user1, user2 }; ChallengesUser = new[] { challengeUser1, challengeUser2 }; TherapistTypes = new[] { therapistType1 }; OpeningTimes = new[] { openingTimes1, openingTimes2, openingTimes2, openingTimes2, openingTimes2, openingTimes2, openingTimes2 }; // Create DTO's AddUserDTO = new AddUserDTO { Categories = new List <int>() { 1 }, Company = 1, Email = "*****@*****.**", FamilyName = "test", FirstName = "test", Phone = "0471236548", Therapists = new List <int>() { 1 } }; EditUserDTO = new EditUserDTO { Categories = new List <int>() { 1 }, Email = "*****@*****.**", FamilyName = "test", FirstName = "test", Phone = "0471236548", UserId = 1, Contract = new DateTime() }; AddTherapistDTO = new AddTherapistDTO { City = "test", Email = "test", FirstName = "test", HouseNumber = 1, LastName = "test", PhoneNumber = "test", PostalCode = 9000, Street = "test", TherapistTypeId = 0, Website = "test" }; AddTherapistTypeDTO = new AddTherapistTypeDTO { Categories = new List <int>() { 1 }, Type = "test" }; EditTherapistDTO = new EditTherapistDTO { City = "test", Email = "test", FirstName = "test", HouseNumber = 1, LastName = "test", PhoneNumber = "test", PostalCode = 5000, Street = "test", TherapistId = 0, Website = "test", TherapistTypeId = 0, OpeningTimes = new List <OpeningTimes>() { new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 } } }; EditTherapistTypeDTO = new EditTherapistTypeDTO { Id = 0, Categories = new List <int>() { 0 }, Type = "therapisttype" }; AddCompanyDTO = new AddCompanyDTO { City = "test", Contract = new DateTime(), Country = "test", HouseNumber = 3, Mail = "test", Name = "test", Phone = "test", PostalCode = 9000, Site = "test", Street = "test" }; EditCompanyDTO = new EditCompanyDTO { City = "test", Contract = new DateTime(), Country = "test", HouseNumber = 3, Mail = "test", Name = "test", Phone = "test", PostalCode = 9000, Site = "test", Street = "test", CompanyId = 0, CompanyMembers = new List <User>() { user1, user2 } }; AddChallengeDTO = new AddChallengeDTO { CategoryId = 0, ChallengeImage = "test", Description = "test", Title = "test" }; CompleteChallengeDTO = new CompleteChallengeDTO { ChallengeID = 0, UserID = 0, Rating = 3, Feedback = "test", CompletedOn = CompleteChallengeDate }; ChallengesUserDTO = new ChallengesUserDTO { ChallengeIds = new List <int>() { 0 }, UserId = 0 }; EditAppUserDTO = new EditAppUserDTO { UserId = 1, Email = "*****@*****.**", FamilyName = "test", FirstName = "tests", Phone = "0474139526" }; //UserManager IdentityUser = new IdentityUser(); }