protected void FindTimes_Click(object sender, EventArgs args) { var startTimeInMinutesFromMidnight = int.Parse(StartTime.SelectedValue); var startDate = StartDate.SelectedDate.AddMinutes(startTimeInMinutesFromMidnight); var endTimeInMinutesFromMidnight = int.Parse(EndTime.SelectedValue); var endDate = EndDate.SelectedDate.AddMinutes(endTimeInMinutesFromMidnight); if (!SelectedDatesAndTimesAreValid(startDate, endDate, startTimeInMinutesFromMidnight, endTimeInMinutesFromMidnight)) { return; } // Add the timezone selected to the CRM Contact for next time. var contact = XrmContext.CreateQuery("contact").FirstOrDefault(c => c.GetAttributeValue <Guid>("contactid") == Contact.Id); if (contact == null) { throw new ApplicationException(string.Format("Could not find user contact where contactid equals '{0}'", Contact.Id)); } contact.SetAttributeValue("adx_timezone", int.Parse(TimeZoneSelection.SelectedValue)); XrmContext.UpdateObject(contact); XrmContext.SaveChanges(); var usersMinutesFromGmt = GetUsersMinutesFromGmt(contact.GetAttributeValue <int?>("adx_timezone"), XrmContext); var appointmentRequest = new AppointmentRequest { AnchorOffset = Service.GetAttributeValue <int?>("anchoroffset").GetValueOrDefault(), Direction = SearchDirection.Forward, Duration = Service.GetAttributeValue <int?>("duration").GetValueOrDefault(60), NumberOfResults = 10, RecurrenceDuration = endTimeInMinutesFromMidnight - startTimeInMinutesFromMidnight, RecurrenceTimeZoneCode = contact.GetAttributeValue <int?>("adx_timezone").GetValueOrDefault(), SearchRecurrenceRule = "FREQ=DAILY;INTERVAL=1", SearchRecurrenceStart = new DateTime(startDate.AddMinutes(usersMinutesFromGmt * -1).Ticks, DateTimeKind.Utc), SearchWindowEnd = new DateTime(endDate.AddMinutes(usersMinutesFromGmt * -1).Ticks, DateTimeKind.Utc), ServiceId = Service.GetAttributeValue <Guid>("serviceid") }; var service = XrmContext; var searchRequest = new OrganizationRequest("Search"); searchRequest.Parameters["AppointmentRequest"] = appointmentRequest; var searchResults = (SearchResults)service.Execute(searchRequest).Results["SearchResults"]; var schedules = searchResults.Proposals.Select(proposal => new { ScheduledStart = proposal.Start.GetValueOrDefault().ToUniversalTime().AddMinutes(usersMinutesFromGmt), ScheduledStartUniversalTime = proposal.Start.GetValueOrDefault().ToUniversalTime(), ScheduledEnd = proposal.End.GetValueOrDefault().ToUniversalTime().AddMinutes(usersMinutesFromGmt), ScheduledEndUniversalTime = proposal.End.GetValueOrDefault().ToUniversalTime(), AvailableResource = proposal.ProposalParties.First().ResourceId }).Where(proposal => proposal.ScheduledStartUniversalTime >= DateTime.UtcNow); if (!schedules.Any()) { SearchPanel.Visible = true; NoTimesMessage.Visible = true; ResultsDisplay.Visible = false; return; } AvailableTimes.DataSource = schedules; AvailableTimes.DataBind(); SearchPanel.Visible = false; ResultsDisplay.Visible = true; ScheduleServiceButton.Enabled = false; }
protected void FindTimes_Click(object sender, EventArgs args) { var startTimeInMinutesFromMidnight = int.Parse(StartTime.SelectedValue); var startDate = StartDate.SelectedDate.AddMinutes(startTimeInMinutesFromMidnight); var endTimeInMinutesFromMidnight = int.Parse(EndTime.SelectedValue); var endDate = EndDate.SelectedDate.AddMinutes(endTimeInMinutesFromMidnight); if (!SelectedDatesAndTimesAreValid(startDate, endDate, startTimeInMinutesFromMidnight, endTimeInMinutesFromMidnight)) { return; } // Add the timezone selected to the CRM Contact for next time. var contact = XrmContext.ContactSet.FirstOrDefault(c => c.ContactId == Contact.Id); contact.Adx_TimeZone = int.Parse(TimeZoneSelection.SelectedValue); XrmContext.UpdateObject(contact); XrmContext.SaveChanges(); var usersMinutesFromGmt = GetUsersMinutesFromGmt(contact.Adx_TimeZone, XrmContext); var appointmentRequest = new AppointmentRequest { AnchorOffset = Service.AnchorOffset.GetValueOrDefault(), Direction = SearchDirection.Forward, Duration = Service.Duration.GetValueOrDefault(60), NumberOfResults = 10, RecurrenceDuration = endTimeInMinutesFromMidnight - startTimeInMinutesFromMidnight, RecurrenceTimeZoneCode = contact.Adx_TimeZone.GetValueOrDefault(), SearchRecurrenceRule = "FREQ=DAILY;INTERVAL=1", SearchRecurrenceStart = new DateTime(startDate.AddMinutes(usersMinutesFromGmt * -1).Ticks, DateTimeKind.Utc), SearchWindowEnd = new DateTime(endDate.AddMinutes(usersMinutesFromGmt * -1).Ticks, DateTimeKind.Utc), ServiceId = Service.ServiceId.GetValueOrDefault() }; var service = XrmContext; var searchRequest = new OrganizationRequest("Search"); searchRequest.Parameters["AppointmentRequest"] = appointmentRequest; var searchResults = (SearchResults)service.Execute(searchRequest).Results["SearchResults"]; var schedules = searchResults.Proposals.Select(proposal => new { ScheduledStart = proposal.Start.GetValueOrDefault().ToUniversalTime().AddMinutes(usersMinutesFromGmt), ScheduledStartUniversalTime = proposal.Start.GetValueOrDefault().ToUniversalTime(), ScheduledEnd = proposal.End.GetValueOrDefault().ToUniversalTime().AddMinutes(usersMinutesFromGmt), ScheduledEndUniversalTime = proposal.End.GetValueOrDefault().ToUniversalTime(), AvailableResource = proposal.ProposalParties.First().ResourceId }); AvailableTimes.DataSource = schedules; AvailableTimes.DataBind(); SearchPanel.Visible = false; ResultsDisplay.Visible = true; ScheduleServiceButton.Enabled = false; }
//public static byte[] setInitializerProfilePicture(string endPath) { // // Setting default avatar for all profiles // string path = AppDomain.CurrentDomain.BaseDirectory + endPath; // FileStream file = new FileStream(path, FileMode.Open); // byte[] avatar = null; // using (var binary = new BinaryReader(file)) { // avatar = binary.ReadBytes((int)file.Length); // } // return avatar; //} public static void SeedHouses(ApplicationDbContext context) { // Create the users UserStore <ApplicationUser> store = new UserStore <ApplicationUser>(context); UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(store); House Nova = new House { HouseName = "Nova", Opens = new TimeSpan(06, 00, 00), Closes = new TimeSpan(23, 00, 00) }; House Lang = new House { HouseName = "Långhuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Teknik = new House { HouseName = "Teknikhuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Gymnastik = new House { HouseName = "Gymnastikhuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Forum = new House { HouseName = "Forumhuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Prisma = new House { HouseName = "Prismahuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Bilbergska = new House { HouseName = "Bilbergska", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Test = new House { HouseName = "Test", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; context.Houses.AddRange(new[] { Nova, Lang, Teknik, Gymnastik, Forum, Prisma, Bilbergska, Test }); context.SaveChanges(); HouseRoom N2037 = new HouseRoom { Id = "N2037", HouseId = Nova.Id, Projector = true, WhiteBoard = true }; HouseRoom L111 = new HouseRoom { Id = "L1112", HouseId = Lang.Id, Projector = true, WhiteBoard = true }; HouseRoom T133 = new HouseRoom { Id = "T133", HouseId = Teknik.Id, Projector = true, WhiteBoard = true }; HouseRoom G108 = new HouseRoom { Id = "G108", HouseId = Gymnastik.Id, Projector = false, WhiteBoard = true }; HouseRoom F138 = new HouseRoom { Id = "F138", HouseId = Forum.Id, Projector = true, WhiteBoard = true }; HouseRoom P104 = new HouseRoom { Id = "P104", HouseId = Prisma.Id, Projector = false, WhiteBoard = true }; HouseRoom B187 = new HouseRoom { Id = "B187", HouseId = Bilbergska.Id, Projector = false, WhiteBoard = false }; context.Rooms.AddRange(new[] { N2037, L111, T133, G108, F138, P104, B187 }); context.SaveChanges(); AvailableTimes Time1 = new AvailableTimes { RoomId = N2037.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time2 = new AvailableTimes { RoomId = L111.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time3 = new AvailableTimes { RoomId = T133.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time4 = new AvailableTimes { RoomId = G108.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time5 = new AvailableTimes { RoomId = F138.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time6 = new AvailableTimes { RoomId = P104.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time7 = new AvailableTimes { RoomId = B187.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; context.FreeIntervals.AddRange(new[] { Time1, Time2, Time3, Time4, Time5, Time6, Time7 }); context.SaveChanges(); //ApplicationUser eliasU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**", //}; //manager.Create(eliasU, "password"); //ApplicationUser nicoU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(nicoU, "password"); //ApplicationUser oskarU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(oskarU, "password"); //ApplicationUser randomU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(randomU, "password"); //ApplicationUser corazonU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(corazonU, "password"); //ApplicationUser andreasU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(andreasU, "password"); //ApplicationUser mathiasU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(mathiasU, "password"); //ApplicationUser lightU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(lightU, "password"); //ApplicationUser hakU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(hakU, "password"); //ApplicationUser alfonsU = new ApplicationUser { // UserName = "******", // Email = "*****@*****.**" //}; //manager.Create(alfonsU, "password"); //// Define friendships //FriendModels friends1 = new FriendModels { // UserId = nicoU.Id, // FriendId = oskarU.Id, // FriendCategory = category1.Id //}; //FriendModels friends2 = new FriendModels { // UserId = nicoU.Id, // FriendId = eliasU.Id, // FriendCategory = category2.Id //}; //FriendModels friends3 = new FriendModels { // UserId = eliasU.Id, // FriendId = corazonU.Id, // FriendCategory = category3.Id //}; //FriendModels friends4 = new FriendModels { // UserId = oskarU.Id, // FriendId = randomU.Id, // FriendCategory = category1.Id //}; //FriendModels friends5 = new FriendModels { // UserId = oskarU.Id, // FriendId = alfonsU.Id, // FriendCategory = category1.Id //}; //FriendModels friends6 = new FriendModels { // UserId = eliasU.Id, // FriendId = lightU.Id, // FriendCategory = category1.Id //}; //FriendModels friends7 = new FriendModels { // UserId = andreasU.Id, // FriendId = eliasU.Id, // FriendCategory = category1.Id //}; //FriendModels friends8 = new FriendModels { // UserId = nicoU.Id, // FriendId = hakU.Id, // FriendCategory = category1.Id //}; //context.Friends.AddRange(new[] { friends1, friends2, friends3, friends4, friends5, friends6, friends7, friends8 }); // Add friendships //context.SaveChanges(); }
public static void SeedHouses(ApplicationDbContext context) { House Nova = new House { HouseName = "Nova", Opens = new TimeSpan(06, 00, 00), Closes = new TimeSpan(23, 00, 00) }; House Lang = new House { HouseName = "Långhuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Teknik = new House { HouseName = "Teknikhuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Gymnastik = new House { HouseName = "Gymnastikhuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Forum = new House { HouseName = "Forumhuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Prisma = new House { HouseName = "Prismahuset", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Bilbergska = new House { HouseName = "Bilbergska", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; House Test = new House { HouseName = "Test", Opens = new TimeSpan(00, 00, 00), Closes = new TimeSpan(23, 59, 59) }; context.Houses.AddRange(new[] { Nova, Lang, Teknik, Gymnastik, Forum, Prisma, Bilbergska, Test }); context.SaveChanges(); HouseRoom N2037 = new HouseRoom { Id = "N2037", HouseId = Nova.Id, Projector = true, WhiteBoard = true }; HouseRoom L111 = new HouseRoom { Id = "L1112", HouseId = Lang.Id, Projector = true, WhiteBoard = true }; HouseRoom T133 = new HouseRoom { Id = "T133", HouseId = Teknik.Id, Projector = true, WhiteBoard = true }; HouseRoom G108 = new HouseRoom { Id = "G108", HouseId = Gymnastik.Id, Projector = false, WhiteBoard = true }; HouseRoom F138 = new HouseRoom { Id = "F138", HouseId = Forum.Id, Projector = true, WhiteBoard = true }; HouseRoom P104 = new HouseRoom { Id = "P104", HouseId = Prisma.Id, Projector = false, WhiteBoard = true }; HouseRoom B187 = new HouseRoom { Id = "B187", HouseId = Bilbergska.Id, Projector = false, WhiteBoard = false }; context.Rooms.AddRange(new[] { N2037, L111, T133, G108, F138, P104, B187 }); context.SaveChanges(); AvailableTimes Time1 = new AvailableTimes { RoomId = N2037.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time2 = new AvailableTimes { RoomId = L111.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time3 = new AvailableTimes { RoomId = T133.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time4 = new AvailableTimes { RoomId = G108.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time5 = new AvailableTimes { RoomId = F138.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time6 = new AvailableTimes { RoomId = P104.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; AvailableTimes Time7 = new AvailableTimes { RoomId = B187.Id, From = new TimeSpan(09, 00, 00), To = new TimeSpan(10, 00, 00) }; context.FreeIntervals.AddRange(new[] { Time1, Time2, Time3, Time4, Time5, Time6, Time7 }); context.SaveChanges(); }
public IActionResult AvailableTime(int iPageNum = 1) { //get today's date to write in all the times DateTime today = DateTime.Now; //make a list of available time classes, don't set the IsAvailable attribute yet - use the view model TimeSlot.cs List <TimeSlot> datesList = new List <TimeSlot>(); //this loop will go through and add all the times to the list that we will generate to show a week schedule for (int i = 0; i < +7; i++) { for (int j = 8; j <= 20; j++) { //make sure that we're keeping the days/months/years accurate DateTime nextDay = today.AddDays(i); //could use a separate class that just has a time and a bool with it, simplifying it and it wouldn't be included in the database - just for the view DateTime nextDateTime = new DateTime(nextDay.Year, nextDay.Month, nextDay.Day, j, 0, 0); //if we use this class, whic I'm not sure i'm going to do AvailableTimes Availtime = new AvailableTimes(); Availtime.SelectedDate = new DateTime(nextDay.Year, nextDay.Month, nextDay.Day, j, 0, 0); Availtime.SelectTime = new TimeSpan(j); //datesList.Add(Availtime); //this will be used if we stick with using the available times class datesList.Add(new TimeSlot(nextDateTime)); } } //go through this loop for each item in the signups repo and compare with the dates listed - if they are the same, then the dates rendered in the view will be unavailable - else, the default : available foreach (var NormalDay in datesList) { if (DateTime.Compare(NormalDay.DateTimeSlot, DateTime.Now) <= 0) { NormalDay.IsAvailable = false; } foreach (var signUp in _repository.SignUps) { if (DateTime.Compare(signUp.availableTimes, NormalDay.DateTimeSlot) == 0) { NormalDay.IsAvailable = false; } } } //going to compare with the repository work, and then if it doesn't match it will be marked true. otherwise, false //want some paging in the main view of the times /*return View(new TimeSlotViewModel * { * TimeSlots = datesList, * PagingInfo = new PagingInfo * { * CurrentPage = iPageNum, * ItemsPerPage = iPageSize, * TotalNumItems = _repository.SignUps.Count() * } * });*/ return(View(datesList)); }