//Returnerar en TimeBookedModel med bokningsystem och deras lediga tider 1h innan och efter gjord bokning public async Task <List <Suggestion> > CreateTimesForSuggestions(BookingTableEntity bookingTable, List <ArticleEntity> listOfArticles) { var listOfSuggestions = new List <Suggestion>(); foreach (var item in listOfArticles) { var time = new Times { StartTime = bookingTable.StartTime, EndTime = bookingTable.EndTime }; var suggestion = new Suggestion(); suggestion.ListOfTimes = await CreateTimes(item, bookingTable); suggestion.Article = item; suggestion.Date = bookingTable.Date; suggestion.BookingSystem = await new BookingSystemRepo().GetBookingSystemFromArticleAsync(item.ArticleId); if (suggestion.ListOfTimes.Count() > 0) { listOfSuggestions.Add(suggestion); } } return(listOfSuggestions); }
public async void AddBooking(BookingTableEntity bookingTable) { var url = "http://localhost:60295/api/addbooking/"; var content = new StringContent(JsonConvert.SerializeObject(bookingTable), Encoding.UTF8, "application/json"); var result = client.PostAsync(url, content); }
//skickar in en model, med tiden man har valt. public async Task <ActionResult> TimeBooked(DateTime date, DateTime startTime, DateTime endTime, int articleId) { var bookingSystem = await new ArticleController().GetBookingSystemFromArticle(articleId); var bookingTable = new BookingTableEntity { ArticleId = articleId, Date = date, StartTime = startTime, EndTime = endTime, BookingSystemId = bookingSystem.BookningSystemId }; await Task.Run(() => AddBooking(bookingTable)); var suggestionViewModel = new SuggestionViewModel(); suggestionViewModel.ListOfSuggestionsFromDifferentBookingSystems = await GetSuggestionsFromDifferentBookingSystems(bookingTable); suggestionViewModel.Article = await new ArticleRepo().GetArticleAsync(articleId); suggestionViewModel.BookingTable = bookingTable; suggestionViewModel.ListOfSuggestionsFromSameBookingSystems = await GetSuggestionsFromSameBookingSystem(bookingTable); suggestionViewModel.BookingSystem = bookingSystem; return(View(suggestionViewModel)); }
public async Task <List <Suggestion> > GetSuggestionsFromSameBookingSystem(BookingTableEntity bookingTable) { var bookingSystem = await new BookingSystemRepo().GetBookingSystemFromArticleAsync(bookingTable.ArticleId); var listOfArticles = await GetDifferentArticlesFromBookingSystem(bookingTable); var listOfRandomizedArticles = await RandomizeArticles(listOfArticles); var listOfSuggestions = await CreateTimesForSuggestions(bookingTable, listOfRandomizedArticles); return(listOfSuggestions); }
public async Task <List <Times> > CreateTimes(ArticleEntity article, BookingTableEntity bookingTable) { var listOfTimes = new List <Times>(); DateTime startTime = bookingTable.StartTime.AddMinutes(-article.Length); DateTime endTime = startTime.AddMinutes(article.Length); DateTime openingTime = SetOpeningTime(bookingTable.Date); DateTime closingTime = SetClosingTime(bookingTable.Date); var bookingSystem = await new BookingSystemRepo().GetBookingSystemAsync(article.BookingSystemId); var listOfBookingTables = await new BookingRepo().GetBookingTablesFromOneDayAndOneBookingSystem(bookingSystem.BookningSystemId, bookingTable.Date); for (int i = 0; i < 3; i++) { if (startTime != bookingTable.StartTime && startTime >= openingTime && endTime <= closingTime) { var time = new Times(); time.StartTime = startTime; time.EndTime = endTime; var checkIfTimeIsBookedModel = new CheckIfTimeIsBokedModel(); checkIfTimeIsBookedModel.Times = time; checkIfTimeIsBookedModel.ListOfBookingTables = listOfBookingTables; time.TimeBooked = await new BookingRepo().CheckIfTimeIsBookedAsync(checkIfTimeIsBookedModel); if (!time.TimeBooked) { listOfTimes.Add(time); } } if (i == 1) { var bookedArticle = await new ArticleRepo().GetArticleAsync(bookingTable.ArticleId); startTime = startTime.AddMinutes(bookedArticle.Length); endTime = endTime.AddMinutes(bookedArticle.Length); } else { startTime = startTime.AddMinutes(article.Length); endTime = endTime.AddMinutes(article.Length); } } return(listOfTimes); }
public async Task <List <Suggestion> > GetSuggestionsFromSameBookingSystem(BookingTableEntity bookingTable) { var url = "http://localhost:60295/api/getsuggestionsfromsamebookingsystem/"; var content = new StringContent(JsonConvert.SerializeObject(bookingTable), Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); string result = await response.Content.ReadAsStringAsync(); var listOfSuggestions = JsonConvert.DeserializeObject <List <Suggestion> >(result); if (response.IsSuccessStatusCode) { return(listOfSuggestions); } return(listOfSuggestions); }
//Returnerar en list med alla bookningssystem som ligger inom en 5km radius public async Task <List <BookingSystemEntity> > ListOfBookingSystemsInRadius(List <BookingSystemEntity> listOfIncBookingSystems, BookingTableEntity bookingTable) { var listOfBookingSystems = new List <BookingSystemEntity>(); var bookingSystem = await new BookingSystemRepo().GetBookingSystemFromArticleAsync(bookingTable.ArticleId); foreach (var item in listOfIncBookingSystems) { var distance = await DistanceTo(bookingSystem.Latitude, bookingSystem.Longitude, item.Latitude, item.Longitude); if (distance <= 5) { listOfBookingSystems.Add(item); } } return(listOfBookingSystems); }
public async Task <List <ArticleEntity> > GetDifferentArticlesFromBookingSystem(BookingTableEntity bookingTable) { var article = await new ArticleRepo().GetArticleAsync(bookingTable.ArticleId); var bookingSystem = await new BookingSystemRepo().GetBookingSystemFromArticleAsync(bookingTable.ArticleId); var listOfArticles = await new ArticleRepo().GetDifferentArticlesFromBookingSystem(bookingSystem.BookningSystemId, article.Service); return(listOfArticles); }
public void AddBooking(BookingTableEntity bookingTable) { context.BookingTabels.Add(bookingTable); context.SaveChanges(); }
public async Task <List <ArticleEntity> > ServiceTypeBeuty(List <BookingSystemEntity> listOfBookingSystem, BookingTableEntity bookingTable, BookingSystemEntity bookingSystem) { var listOfArticles = new List <ArticleEntity>(); var hairdresserListOfBookingSystem = new List <BookingSystemEntity>(); var massageListOfBookingSystem = new List <BookingSystemEntity>(); var beutySalonListOfBookingSystem = new List <BookingSystemEntity>(); foreach (var item in listOfBookingSystem) { if (item.ServiceType == 1) { hairdresserListOfBookingSystem.Add(item); } if (item.ServiceType == 2) { massageListOfBookingSystem.Add(item); } if (item.ServiceType == 3) { beutySalonListOfBookingSystem.Add(item); } } var hairdresserListOfArticles = await GetArticlesFromBookingSystems(hairdresserListOfBookingSystem, bookingTable, bookingSystem); var massageListOfArticles = await GetArticlesFromBookingSystems(massageListOfBookingSystem, bookingTable, bookingSystem); var beutySalondListOfArticles = await GetArticlesFromBookingSystems(beutySalonListOfBookingSystem, bookingTable, bookingSystem); if (hairdresserListOfArticles.Count() > 0) { listOfArticles.Add(await RandomizeOneArticle(hairdresserListOfArticles)); } if (massageListOfArticles.Count() > 0) { listOfArticles.Add(await RandomizeOneArticle(massageListOfArticles)); } if (beutySalondListOfArticles.Count() > 0) { listOfArticles.Add(await RandomizeOneArticle(beutySalondListOfArticles)); } return(listOfArticles); }
public async Task <List <ArticleEntity> > ServiceTypeCar(List <BookingSystemEntity> listOfBookingSystem, BookingTableEntity bookingTable, BookingSystemEntity bookingSystem) { var listOfArticles = new List <ArticleEntity>(); var workshopListOfBookingSystem = new List <BookingSystemEntity>(); var carWashListOfBookingSystem = new List <BookingSystemEntity>(); foreach (var item in listOfBookingSystem) { if (item.ServiceType == 4) { workshopListOfBookingSystem.Add(item); } if (item.ServiceType == 5) { carWashListOfBookingSystem.Add(item); } } var workshopListOfArticles = await GetArticlesFromBookingSystems(workshopListOfBookingSystem, bookingTable, bookingSystem); var carWashListOfArticles = await GetArticlesFromBookingSystems(carWashListOfBookingSystem, bookingTable, bookingSystem); if (workshopListOfArticles.Count() > 0) { listOfArticles.Add(await RandomizeOneArticle(workshopListOfArticles)); } if (carWashListOfArticles.Count() > 0) { listOfArticles.Add(await RandomizeOneArticle(carWashListOfArticles)); } return(listOfArticles); }
public async Task <List <ArticleEntity> > GetArticlesFromBookingSystemsBasedOnServiceType(BookingTableEntity bookingTable, List <BookingSystemEntity> listOfBookingSystems) { var bookingSystem = await new BookingSystemRepo().GetBookingSystemFromArticleAsync(bookingTable.ArticleId); var listOfArticles = new List <ArticleEntity>(); if (bookingSystem.ServiceType == 5 || bookingSystem.ServiceType == 4) { listOfArticles = await ServiceTypeCar(listOfBookingSystems, bookingTable, bookingSystem); } if (bookingSystem.ServiceType == 1 || bookingSystem.ServiceType == 2 || bookingSystem.ServiceType == 3) { listOfArticles = await ServiceTypeBeuty(listOfBookingSystems, bookingTable, bookingSystem); } if (listOfArticles.Count() < 3) { listOfArticles = await FillListWithRandomArticles(listOfArticles, listOfBookingSystems, bookingSystem.ServiceType); } return(listOfArticles); }
public async Task <List <Suggestion> > GetSuggestionsFromDifferentBookingSystems(BookingTableEntity bookingTable) { var bookingSystem = await new BookingSystemRepo().GetBookingSystemFromArticleAsync(bookingTable.ArticleId); var listOfBookingSystemFromSameCity = await new BookingSystemRepo().GetSuggestedServicesAsync(bookingSystem); var listOfBookingSystemInRadius = await ListOfBookingSystemsInRadius(listOfBookingSystemFromSameCity, bookingTable); var listOfArticles = await GetArticlesFromBookingSystemsBasedOnServiceType(bookingTable, listOfBookingSystemInRadius); var listOfRandomizedArticles = await RandomizeArticles(listOfArticles); var listOfSuggestions = await CreateTimesForSuggestions(bookingTable, listOfRandomizedArticles); return(listOfSuggestions); }
public async Task <IHttpActionResult> AddBooking(BookingTableEntity bookingTable) { await Task.Run(() => new BookingRepo().AddBooking(bookingTable)); return(Ok()); }
public async Task <List <ArticleEntity> > GetArticlesFromBookingSystems(List <BookingSystemEntity> listOfBookingSystems, BookingTableEntity bookingTable, BookingSystemEntity bookingSystem) { var listOfArticles = new List <ArticleEntity>(); var tempListOfArticles = new List <ArticleEntity>(); var article = await new ArticleRepo().GetArticleAsync(bookingTable.ArticleId); foreach (var item in listOfBookingSystems) { if (item.ServiceType == bookingSystem.ServiceType) { tempListOfArticles = await new ArticleRepo().GetDifferentArticlesFromBookingSystem(item.BookningSystemId, article.Service); } else { tempListOfArticles = await new ArticleRepo().GetArticlesFromBookingSystemAsync(item.BookningSystemId); } foreach (var i in tempListOfArticles) { listOfArticles.Add(i); } } return(listOfArticles); }
public async Task <IHttpActionResult> GetSuggestionsFromDifferentBookingSystems(BookingTableEntity bookingTable) { var listOfSuggestions = await new SuggestionRepo().GetSuggestionsFromDifferentBookingSystems(bookingTable); return(Ok(listOfSuggestions)); }
protected override void Seed(ApplicationDbContext context) { var bookingsystem1 = new BookingSystemEntity() { ServiceType = 4, BookningSystemId = 1, SystemName = "Bil och Däck", SystemDescription = "Verkstad", Email = "*****@*****.**", PhoneNumber = "070-000 00 00", Website = "www.bilochdack.se", CompanyName = "Bil och Däck", ContactEmail = "*****@*****.**", ContactPhone = "070-000 00 00", Adress = "Glanshammarsvägen 16", Latitude = 59.294810, Longitude = 15.231510, PostaICode = "703 64", City = "Örebro", }; context.BookingSystems.Add(bookingsystem1); var bookingsystem2 = new BookingSystemEntity() { ServiceType = 1, BookningSystemId = 2, SystemName = "Salong Klipp", SystemDescription = "Frisör", Email = "*****@*****.**", PhoneNumber = "070-000 00 00", Website = "www.salongklipp.se", CompanyName = "Salong Klipp", ContactEmail = "*****@*****.**", ContactPhone = "070-000 00 00", Adress = "Skolgatan 42", Latitude = 59.280750, Longitude = 15.223650, PostaICode = "703 64", City = "Örebro", }; context.BookingSystems.Add(bookingsystem2); var bookingsystem3 = new BookingSystemEntity() { ServiceType = 1, BookningSystemId = 3, SystemName = "Klipp och Trimm", SystemDescription = "Frisör", Email = "*****@*****.**", PhoneNumber = "070-000 00 00", Website = "www.klippochtrimm.se", CompanyName = "Klipp och Trimm", ContactEmail = "*****@*****.**", ContactPhone = "070-000 00 00", Adress = "Sandkullsvägen 24", Latitude = 59.382580, Longitude = 17.917903, PostaICode = "703 64", City = "Stockholm", }; context.BookingSystems.Add(bookingsystem3); var bookingsystem4 = new BookingSystemEntity() { ServiceType = 2, BookningSystemId = 4, SystemName = "Saras Massage", SystemDescription = "Massage", Email = "*****@*****.**", PhoneNumber = "070-000 00 00", Website = "www.sarasmassage.se", CompanyName = "Saras Massage", ContactEmail = "*****@*****.**", ContactPhone = "070-000 00 00", Adress = "Glanshammarsvägen 16", Latitude = 59.294810, Longitude = 15.231510, PostaICode = "703 64", City = "Örebro", }; context.BookingSystems.Add(bookingsystem4); var bookingsystem5 = new BookingSystemEntity() { ServiceType = 3, BookningSystemId = 5, SystemName = "Stefans Skön och Fin", SystemDescription = "Skönhetssalong", Email = "*****@*****.**", PhoneNumber = "070-000 00 00", Website = "www.stefansskonochfin.se", CompanyName = "Stefans Skön och Fin", ContactEmail = "*****@*****.**", ContactPhone = "070-000 00 00", Adress = "Skolgatan 42", Latitude = 59.281750, Longitude = 15.223650, PostaICode = "703 64", City = "Örebro", }; context.BookingSystems.Add(bookingsystem5); var bookingsystem6 = new BookingSystemEntity() { ServiceType = 3, BookningSystemId = 6, SystemName = "Salong Finast", SystemDescription = "Skönhetssalong", Email = "*****@*****.**", PhoneNumber = "070-000 00 00", Website = "www.salongfinast.se", CompanyName = "Salong Finast", ContactEmail = "*****@*****.**", ContactPhone = "070-000 00 00", Adress = "Skolgatan 42", Latitude = 59.280750, Longitude = 15.233650, PostaICode = "703 64", City = "Örebro", }; context.BookingSystems.Add(bookingsystem6); var bookingsystem7 = new BookingSystemEntity() { ServiceType = 5, BookningSystemId = 7, SystemName = "Aspholmens Biltvätt", SystemDescription = "Biltvätt", Email = "*****@*****.**", PhoneNumber = "070-000 00 00", Website = "www.aspholmensbiltvatt.se", CompanyName = "Aspholmens Biltvätt", ContactEmail = "*****@*****.**", ContactPhone = "070-000 00 00", Adress = "Skolgatan 42", Latitude = 59.280750, Longitude = 15.233650, PostaICode = "703 64", City = "Örebro", }; context.BookingSystems.Add(bookingsystem7); var bookedTime1 = new BookingTableEntity() { BookingTableId = 1, Date = DateTime.Now, StartTime = DateTime.Now, EndTime = DateTime.Now, ArticleId = 1 }; context.BookingTabels.Add(bookedTime1); var bookedTime2 = new BookingTableEntity() { BookingTableId = 1, Date = DateTime.Now, StartTime = DateTime.Now, EndTime = DateTime.Now, ArticleId = 1 }; context.BookingTabels.Add(bookedTime2); var article1 = new ArticleEntity() { ArticleId = 1, Name = "Däck Byte", Length = 20, Price = 150, BookingSystemId = 1, Service = 1 }; context.Articles.Add(article1); var article2 = new ArticleEntity() { ArticleId = 2, Name = "Service", Length = 60, Price = 1000, BookingSystemId = 1, Service = 1 }; context.Articles.Add(article2); var article3 = new ArticleEntity() { ArticleId = 3, Name = "Besiktning", Length = 30, Price = 600, BookingSystemId = 1, Service = 2 }; context.Articles.Add(article3); var article4 = new ArticleEntity() { ArticleId = 4, Name = "Herrklippning", Length = 20, Price = 300, BookingSystemId = 2, Service = 1 }; context.Articles.Add(article4); var article5 = new ArticleEntity() { ArticleId = 5, Name = "Damklippning", Length = 30, Price = 400, BookingSystemId = 2, Service = 1 }; context.Articles.Add(article5); var article6 = new ArticleEntity() { ArticleId = 6, Name = "Permanenta", Length = 60, Price = 700, BookingSystemId = 2, Service = 2 }; context.Articles.Add(article6); var article7 = new ArticleEntity() { ArticleId = 7, Name = "Herrklippning", Length = 20, Price = 300, BookingSystemId = 3, Service = 1 }; context.Articles.Add(article7); var article8 = new ArticleEntity() { ArticleId = 8, Name = "Damklippning", Length = 30, Price = 400, BookingSystemId = 3, Service = 1 }; context.Articles.Add(article8); var article9 = new ArticleEntity() { ArticleId = 9, Name = "Permanenta", Length = 60, Price = 700, BookingSystemId = 3, Service = 2 }; context.Articles.Add(article9); var article10 = new ArticleEntity() { ArticleId = 10, Name = "Svensk Massage", Length = 30, Price = 500, BookingSystemId = 4, Service = 1 }; context.Articles.Add(article10); var article11 = new ArticleEntity() { ArticleId = 11, Name = "Thailändsk Massage", Length = 30, Price = 500, BookingSystemId = 4, Service = 1 }; context.Articles.Add(article11); var article12 = new ArticleEntity() { ArticleId = 12, Name = "Kiropraktor", Length = 45, Price = 600, BookingSystemId = 4, Service = 2 }; context.Articles.Add(article12); var article13 = new ArticleEntity() { ArticleId = 13, Name = "Ansiktsbehandling", Length = 30, Price = 400, BookingSystemId = 5, Service = 1 }; context.Articles.Add(article13); var article14 = new ArticleEntity() { ArticleId = 14, Name = "Ansiktsmask", Length = 30, Price = 350, BookingSystemId = 5, Service = 1 }; context.Articles.Add(article14); var article15 = new ArticleEntity() { ArticleId = 15, Name = "Pedekyr", Length = 30, Price = 300, BookingSystemId = 5, Service = 2 }; context.Articles.Add(article15); var article16 = new ArticleEntity() { ArticleId = 16, Name = "Ansiktsbehandling", Length = 30, Price = 400, BookingSystemId = 6, Service = 1 }; context.Articles.Add(article16); var article17 = new ArticleEntity() { ArticleId = 17, Name = "Ansiktsmask", Length = 30, Price = 350, BookingSystemId = 6, Service = 1 }; context.Articles.Add(article17); var article18 = new ArticleEntity() { ArticleId = 18, Name = "Pedekyr", Length = 30, Price = 300, BookingSystemId = 6, Service = 2 }; context.Articles.Add(article18); var article19 = new ArticleEntity() { ArticleId = 19, Name = "Biltvätt", Length = 20, Price = 200, BookingSystemId = 7, Service = 1 }; context.Articles.Add(article19); var article20 = new ArticleEntity() { ArticleId = 20, Name = "Städning", Length = 15, Price = 150, BookingSystemId = 7, Service = 1 }; context.Articles.Add(article20); var article21 = new ArticleEntity() { ArticleId = 21, Name = "Biltvätt och Städning", Length = 45, Price = 300, BookingSystemId = 7, Service = 1 }; context.Articles.Add(article21); var article22 = new ArticleEntity() { ArticleId = 22, Name = "Waxning", Length = 30, Price = 300, BookingSystemId = 7, Service = 2 }; context.Articles.Add(article22); context.SaveChanges(); base.Seed(context); }