private bool OneTable() { var distinctCourseTitles = Shortlist .GroupBy(model => model.Course.Title) .Select(models => models.Key) .ToList(); if (distinctCourseTitles.Count > 1) { return(false); } var distinctCourseLevels = Shortlist .GroupBy(model => model.Course.Level) .Select(models => models.Key) .ToList(); if (distinctCourseLevels.Count > 1) { return(false); } var distinctLocations = Shortlist .GroupBy(model => model.LocationDescription) .Select(models => models.Key) .ToList(); if (distinctLocations.Count > 1) { return(false); } return(true); }
public void SelectWinner(int nominationId, string winningComment, string hrAdminsFeedback, int adminId) { var shortlistedNomination = _encourageDatabaseContext.Query <Shortlist>().SingleOrDefault(model => model.NominationId == nominationId); var currentNomination = shortlistedNomination != null?_encourageDatabaseContext.Query <Nomination>().FirstOrDefault(x => x.Id == shortlistedNomination.NominationId) : _encourageDatabaseContext .Query <Nomination>().FirstOrDefault(x => x.Id == nominationId); if (currentNomination != null) { var customDate = _customDateService.GetCustomDate(currentNomination.AwardId); if (shortlistedNomination != null) { shortlistedNomination.IsWinner = true; shortlistedNomination.WinningDate = customDate.Date; shortlistedNomination.WinningComment = winningComment; shortlistedNomination.HrAdminsFeedback = hrAdminsFeedback; shortlistedNomination.AdminId = adminId; _encourageDatabaseContext.Update <Shortlist>(shortlistedNomination); } else { var winner = new Shortlist() { IsWinner = true, NominationId = nominationId, //WinningDate = DateTime.Now.Date, WinningDate = customDate.Date, WinningComment = winningComment, HrAdminsFeedback = hrAdminsFeedback, AdminId = adminId }; _encourageDatabaseContext.Add <Shortlist>(winner); } } }
public async Task Then_The_Item_Is_Retrieved_By_Unique_Key( Shortlist item, List <Shortlist> recordsInDb, [Frozen] Mock <ICourseDeliveryReadonlyDataContext> mockContext, Data.Repository.ShortlistRepository repository) { //Arrange recordsInDb = recordsInDb.Select(c => { c.ShortlistUserId = item.ShortlistUserId; return(c); }).ToList(); recordsInDb[0].StandardId = item.StandardId; recordsInDb[0].Ukprn = item.Ukprn; recordsInDb[0].Lat = item.Lat; recordsInDb[0].Long = item.Long; mockContext .Setup(context => context.Shortlists) .ReturnsDbSet(recordsInDb); //Act var actual = await repository.GetShortlistUserItem(item); //Assert actual.Should() .BeEquivalentTo(recordsInDb.First(shortlist => shortlist.ShortlistUserId == item.ShortlistUserId && shortlist.Ukprn.Equals(item.Ukprn) && shortlist.StandardId.Equals(item.StandardId) && shortlist.Lat.Equals(item.Lat) && shortlist.Long.Equals(item.Long) )); }
public void Then_If_No_Location_Then_Delivery_Modes_Are_Not_Filtered( Shortlist source, DeliveryType deliveryType1, DeliveryType deliveryType2, DeliveryType deliveryType3) { //Arrange source.LocationDescription = string.Empty; deliveryType1.Radius = 5; deliveryType1.DistanceInMiles = 10; source.ProviderLocation.DeliveryTypes = new List <DeliveryType> { deliveryType1, deliveryType2, deliveryType3 }; //Act var actual = (GetShortlistItemResponse)source; //Assert actual.ProviderDetails.DeliveryTypes.Should().BeEquivalentTo(new List <DeliveryType> { deliveryType1, deliveryType2, deliveryType3 }); }
public async Task <IActionResult> Delete(Guid id) { _logger.LogInformation($"DELETE Shortlist with {id}"); try { var shortlist = new Shortlist() { ShortlistId = id }; var lookup = await _context.Shortlist .AsNoTracking() .FirstOrDefaultAsync(sl => sl.ShortlistId == id); if (lookup == default(Shortlist)) { return(NoContent()); } _context.Shortlist.Remove(shortlist); await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(new Response() { Message = ex.Message, Status = "400" })); } return(NoContent()); }
public async Task <IActionResult> Post(Guid id, [FromBody] Shortlist shortlist) { //id is user id! _logger.LogInformation($"POST Shortlist to user with id {id}"); var user = await _context.AppUser.FirstOrDefaultAsync(u => u.Id == id.ToString()); if (user == default(AppUser)) { return(NotFound(new Response() { Message = "A user with that id does not exist.", Status = "404" })); } try { _context.Shortlist.Add(shortlist); shortlist.AppUser = user; await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(new Response() { Message = ex.Message, Status = "400" })); } return(CreatedAtAction(nameof(Post), new { shortlist.ShortlistId }, shortlist)); }
public void Then_The_DeliveryTypes_Are_Filtered_If_The_Distance_Exceeds_The_Radius_And_There_Is_A_Location( Shortlist source, DeliveryType deliveryType1, DeliveryType deliveryType2, DeliveryType deliveryType3) { //Arrange deliveryType1.Radius = 5; deliveryType1.DistanceInMiles = 10; source.ProviderLocation.DeliveryTypes = new List <DeliveryType> { deliveryType1, deliveryType2, deliveryType3 }; //Act var actual = (GetShortlistItemResponse)source; //Assert actual.ProviderDetails.DeliveryTypes.Should().BeEquivalentTo(new List <DeliveryType> { deliveryType2, deliveryType3 }); }
public async Task <Shortlist> GetShortlistUserItem(Shortlist item) { return(await _readonlyDataContext.Shortlists.SingleOrDefaultAsync(c => c.ShortlistUserId.Equals(item.ShortlistUserId) && c.StandardId.Equals(item.StandardId) && c.Ukprn.Equals(item.Ukprn) && c.Lat.Equals(item.Lat) && c.Long.Equals(item.Long) )); }
public static ShortlistContent CreateShortlistContent( Shortlist shortlist, Content content, int num) { return(new ShortlistContent() { ShortlistId = shortlist.ShortlistId, ContentId = content.ContentId, Number = num }); }
public void Then_The_Fields_Are_Correctly_Mapped(Shortlist source) { var actual = (GetShortlistItemResponse)source; actual.Id.Should().Be(source.Id); actual.ShortlistUserId.Should().Be(source.ShortlistUserId); actual.ProviderDetails.Should().BeEquivalentTo(GetProviderDetailResponse.Map(source.ProviderLocation)); actual.CourseId.Should().Be(source.StandardId); actual.LocationDescription.Should().Be(source.LocationDescription); actual.CreatedDate.Should().Be(source.CreatedDate); }
public static Shortlist CreateShortlist(string name, AppUser user) { var shortlist = new Shortlist() { ShortlistId = Guid.NewGuid(), ListName = name, UserId = user.Id }; return(shortlist); }
private string GetExpiryDateText() { if (!Shortlist.Any()) { return(""); } var dateToUse = Shortlist.Select(c => c.CreatedDate).Max(); return($"We will save your shortlist until {dateToUse.AddDays(ShortlistExpiryInDays):dd MMMM yyyy}."); }
public void ShortlistNomination(int nominationId, int adminId) { var shortlistedNomination = new Shortlist() { IsWinner = false, NominationId = nominationId, HrAdminsFeedback = string.Empty, AdminId = adminId }; _encourageDatabaseContext.Add <Shortlist>(shortlistedNomination); }
public async Task Insert(Shortlist item) { try { await _dataContext.Shortlists.AddAsync(item); _dataContext.SaveChanges(); } catch (DbUpdateException e) { _logger.LogInformation(e, "Unable to add shortlist item"); } }
public void Arrange() { _shortlistItem = new Shortlist { Id = Guid.NewGuid(), ShortlistUserId = Guid.NewGuid() }; _courseDeliveryDataContext = new Mock <ICourseDeliveryDataContext>(); _courseDeliveryDataContext.Setup(x => x.Shortlists).ReturnsDbSet(new List <Shortlist>()); _providerImportRepository = new Data.Repository.ShortlistRepository(Mock.Of <ILogger <Data.Repository.ShortlistRepository> >(), _courseDeliveryDataContext.Object, Mock.Of <ICourseDeliveryReadonlyDataContext>()); }
public async Task <IActionResult> Put(Guid id, [FromBody] Shortlist shortlist) { _logger.LogInformation($"PUT Shortlist Content with {id}"); try { _context.Shortlist.Update(shortlist); await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(new Response() { Message = ex.Message, Status = "400" })); } return(NoContent()); }
public async Task Then_Gets_Shortlist_For_User_From_Mediator( Guid shortlistUserId, GetShortlistForUserResult mediatorResult, [Frozen] Mock <IMediator> mockMediator, [Greedy] ShortlistController controller) { mockMediator .Setup(mediator => mediator.Send( It.Is <GetShortlistForUserQuery>(query => query.ShortlistUserId == shortlistUserId), It.IsAny <CancellationToken>())) .ReturnsAsync(mediatorResult); var controllerResult = await controller.GetAllForUser(shortlistUserId) as ObjectResult; controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.OK); var model = controllerResult.Value as GetShortlistForUserResponse; model !.Shortlist.Should().BeEquivalentTo(mediatorResult.Shortlist.Select(item => (GetShortlistItem)item)); }
public void Then_If_There_Are_No_DeliveryModes_After_Filtering_And_There_Is_A_Location_Then_Not_Found_Delivery_Mode_Added( Shortlist source, DeliveryType deliveryType1) { //Arrange deliveryType1.Radius = 5; deliveryType1.DistanceInMiles = 10; source.ProviderLocation.DeliveryTypes = new List <DeliveryType> { deliveryType1 }; //Act var actual = (GetShortlistItemResponse)source; //Assert actual.ProviderDetails.DeliveryTypes.Should().BeEquivalentTo(new List <DeliveryType> { new DeliveryType { DeliveryModes = "NotFound" } }); }
public void RemoveFromShortlist(Itinerary itinerary) { Shortlist.Remove(itinerary); }
public void Join(Shortlist shortlist, Content content, int num) { shortlistContent.Add( DataFactory.CreateShortlistContent(shortlist, content, num)); }
public void AddToShortlist(Itinerary itinerary) { Shortlist.Add(itinerary); }