public List <ANEventModel> GetEventsInNewFeeds() { var currentUserId = this.CurrentUser.Id; var sandbox = new ANEventSearchingSandbox(this.ANDBUnitOfWork); var results = sandbox.Search(new SearchingSandbox.Model.SearchCriteria() { UserId = currentUserId }); var anEventEntities = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include("User.UserProfiles.Image") .Include("ANEventImages.Image") .Include("ANEventInformations") .Where(x => results.Contains(x.Id)).ToList() .OrderBy(x => results.IndexOf(x.Id)).ToList(); var favoritedEntities = this.ANDBUnitOfWork.ANEventUserFavouriteRepository.GetAll().Where(x => x.ANEventId.HasValue && results.Contains(x.ANEventId.Value) && x.UserId.HasValue && x.UserId.Value == currentUserId).ToList(); var anEventModels = new List <ANEventModel>(); foreach (var entity in anEventEntities) { var anEventModel = ANEventMapper.ToModel(entity); // get host information if (entity.User != null) { anEventModel.Host = UserMapper.ToModel(entity.User); var firstProfile = entity.User.UserProfiles.FirstOrDefault(); anEventModel.Host.Profile = UserProfileMapper.ToModel(firstProfile); if (anEventModel.Host.Profile != null) { anEventModel.Host.Profile.Avatar = ImageMapper.ToModel(firstProfile.Image); } } // get cover image var coverImageEntity = entity.ANEventImages.Where(x => x.ANEventImageType == (int)Common.ANEventImageType.ANEventCoverImage).OrderBy(x => x.SortPriority).FirstOrDefault(); if (coverImageEntity != null) { anEventModel.CoverPhoto = ImageMapper.ToModel(coverImageEntity.Image); } // get information var information = entity.ANEventInformations.FirstOrDefault(); anEventModel.Information = ANEventInformationMapper.ToModel(information); anEventModel.ANEventUserFavourites = ANEventUserFavouriteMapper.ToModel(favoritedEntities.Where(x => x.ANEventId.HasValue && x.ANEventId.Value == anEventModel.Id)); anEventModels.Add(anEventModel); } return(anEventModels); }
public ANEventUserFavouriteModel AddEventToFavourites(AddOrRemoveEventToFavouritesRequestModel request) { var userId = this.CurrentUser.Id; var eventId = request.ANEventId; if (this.ANDBUnitOfWork.ANEventUserFavouriteRepository.GetAll().Any(x => x.ANEventId.HasValue && x.ANEventId.Value == eventId && x.UserId.HasValue && x.UserId.Value == userId)) { return(null); } var entity = new ANEventUserFavourite() { UserId = userId, ANEventId = eventId, CreatedDate = DateTimeHelper.DateTimeNow }; this.ANDBUnitOfWork.ANEventUserFavouriteRepository.Save(entity); this.ANDBUnitOfWork.Commit(); return(ANEventUserFavouriteMapper.ToModel(entity)); }