public async Task <ImageModel> UploadCoverPhoto() { if (!Request.Content.IsMimeMultipartContent()) { return(null); } var currentProfile = this.ANDBUnitOfWork.UserProfileRepository.GetAll().FirstOrDefault(x => x.UserId.HasValue && x.UserId.Value == CurrentUser.Id); if (currentProfile == null) { return(null); } var filesReadToProvider = await Request.Content.ReadAsMultipartAsync(); if (filesReadToProvider.Contents.Count == 0) { return(null); } var stream = await filesReadToProvider.Contents[0].ReadAsStreamAsync(); var fileKey = string.Format("event/cover/cv{0}.png", Guid.NewGuid().ToString()); var image = await this.CreateNewImage(stream, fileKey); return(ImageMapper.ToModel(image)); }
public ANEventDetailHeaderModel GetEventDetailHeader(int Id) { var entity = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include("ANEventInformations") .Include("ANEventImages.Image") .FirstOrDefault(x => x.Id == Id); if (entity == null) { return(null); } var firstInformation = entity.ANEventInformations.FirstOrDefault(); var coverPhoto = entity.ANEventImages.FirstOrDefault(x => x.ANEventImageType == (int)Common.ANEventImageType.ANEventCoverImage); var isPendingMember = this.ANDBUnitOfWork.ANEventRequestToJoinRepository.GetAll().Any(x => x.ANEventId.HasValue && x.ANEventId.Value == Id && x.UserId.HasValue && x.UserId.Value == this.CurrentUser.Id && x.Status == (int)Common.ANRequestToJoinStatus.Waiting); var isMember = this.ANDBUnitOfWork.ANEventMemberRepository.GetAll().Any(x => x.ANEventId.HasValue && x.ANEventId.Value == Id && x.UserId.HasValue && x.UserId.Value == this.CurrentUser.Id); return(new ANEventDetailHeaderModel() { EventID = entity.Id, EventTitle = firstInformation.Title, EventCoverPhoto = ImageMapper.ToModel(coverPhoto != null ? coverPhoto.Image : null), IsHost = entity.UserId.HasValue && this.CurrentUser.Id == entity.UserId.Value, IsPendingMember = isPendingMember, IsMember = isMember }); }
public ANEventDetailRequestToJoinModel GetEventDetailRequestToJoin(int Id) { if (!this.ANDBUnitOfWork.ANEventRepository.GetAll().Any(x => x.Id == Id && x.UserId.HasValue && x.UserId.Value == this.CurrentUser.Id)) { throw new HttpResponseException(HttpStatusCode.Forbidden); } var requestEntity = this.ANDBUnitOfWork.ANEventRequestToJoinRepository.GetAll() .Include("User.UserProfiles.Image") .Where(x => x.ANEventId.HasValue && x.ANEventId.Value == Id && x.Status.HasValue && x.Status.Value == (int)Common.ANRequestToJoinStatus.Waiting).ToList(); var RTJmodels = requestEntity.Select(x => { var firstUserProfile = x.User.UserProfiles.FirstOrDefault(); var anEventRTJModel = ANEventRequestToJoinMapper.ToModel(x); anEventRTJModel.User = UserMapper.ToModel(x.User); if (anEventRTJModel.User != null) { anEventRTJModel.User.Profile = UserProfileMapper.ToModel(firstUserProfile); if (anEventRTJModel.User.Profile != null) { anEventRTJModel.User.Profile.Avatar = ImageMapper.ToModel(firstUserProfile.Image); } } return(anEventRTJModel); }).ToList(); return(new ANEventDetailRequestToJoinModel() { EventId = Id, ANEventRequestToJoins = RTJmodels }); }
public ANEventDetailMemberModel GetEventDetailMember(int Id) { //Thread.Sleep(1000); var entity = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include("ANEventMembers.User.UserProfiles.Image") .FirstOrDefault(x => x.Id == Id); if (entity == null) { return(null); } var listMember = entity.ANEventMembers.Select(x => { var firstUserProfile = x.User.UserProfiles.FirstOrDefault(); var anEventMemberModel = ANEventMemberMapper.ToModel(x); anEventMemberModel.User = UserMapper.ToModel(x.User); if (anEventMemberModel.User != null) { anEventMemberModel.User.Profile = UserProfileMapper.ToModel(firstUserProfile); if (anEventMemberModel.User.Profile != null) { anEventMemberModel.User.Profile.Avatar = ImageMapper.ToModel(firstUserProfile.Image); } } return(anEventMemberModel); } ).ToList(); return(new ANEventDetailMemberModel() { EventId = entity.Id, ANEventMembers = listMember }); }
public List <ANEventModel> GetJoinedEvent() { var hostId = this.CurrentUser.Id; var events = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include(x => x.User) .Include(x => x.User.UserProfiles) .Include("User.UserProfiles.Image") .Include(x => x.ANEventImages) .Include("ANEventImages.Image") .Include("ANEventInformations.ANEventLocation") .Include(x => x.ANEventMembers) .Where(e => e.ANEventMembers.Select(f => f.UserId).Contains(hostId)).OrderByDescending(t => t.CreatedDate).ToList(); var anEventModels = new List <ANEventModel>(); foreach (var ev in events) { var model = new ANEventModel(); model.Id = ev.Id; model.Host = UserMapper.ToModel(ev.User); // get cover image var coverImageEntity = ev.ANEventImages.Where(x => x.ANEventImageType == (int)Common.ANEventImageType.ANEventCoverImage).OrderBy(x => x.SortPriority).FirstOrDefault(); if (coverImageEntity != null) { model.CoverPhoto = ImageMapper.ToModel(coverImageEntity.Image); } var information = ev.ANEventInformations.FirstOrDefault(); model.Information = ANEventInformationMapper.ToModel(information); if (model.Information != null) { model.Information.ANEventLocation = ANEventLocationMapper.ToModel(information.ANEventLocation); } model.CreatedDate = ev.CreatedDate; model.NumberOfMember = ev.ANEventMembers.Count; anEventModels.Add(model); } var groupEvents = anEventModels.GroupBy(t => t.CreatedDate.Year) .Select(gr => new ANEventGroupModel { Year = gr.Key, EventMonth = gr.GroupBy(m => new { m.CreatedDate.Year, m.CreatedDate.Month }) .Select(grm => new ANEventMonthGroup { Month = grm.Key.Month, Events = grm.ToList() }).ToList() }).ToList(); return(anEventModels); }
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 List <ANEventModel> GetMyEventFavourites() { var currentUserId = this.CurrentUser.Id; var anEventEntities = this.ANDBUnitOfWork.ANEventUserFavouriteRepository.GetAll() .Where(x => x.UserId.HasValue && x.UserId.Value == currentUserId) .Select(x => x.ANEvent) .Include("User.UserProfiles.Image") .Include("ANEventImages.Image") .Include("ANEventInformations.ANEventLocation") .ToList() .OrderByDescending(x => x.CreatedDate).ToList(); var anEventModels = new List <ANEventModel>(); var anEventIds = anEventEntities.Select(x => x.Id).ToList(); var numberOfMembers = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Where(x => anEventIds.Contains(x.Id)) .Select(x => new { Id = x.Id, numberOfMember = x.ANEventMembers.Count() }).ToList(); 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.NumberOfMember = numberOfMembers.Where(x => x.Id == anEventModel.Id).Select(x => x.numberOfMember).FirstOrDefault(); anEventModel.Information.ANEventLocation = ANEventLocationMapper.ToModel(information.ANEventLocation); anEventModels.Add(anEventModel); } return(anEventModels); }
public List <ANEventModel> GetEventInWeek() { DateTime input = DateTime.Now; int delta = DayOfWeek.Monday - input.DayOfWeek; int first = input.AddDays(delta).Day; int last = first + 7; var hostId = this.CurrentUser.Id; var events = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include(x => x.User) .Include(x => x.User.UserProfiles) .Include("User.UserProfiles.Image") .Include(x => x.ANEventImages) .Include("ANEventImages.Image") .Include("ANEventInformations.ANEventLocation") .Include(x => x.ANEventMembers) .Where(e => (e.UserId == (hostId) || e.ANEventMembers.Select(f => f.UserId).Contains(hostId)) && e.ANEventInformations.FirstOrDefault().StartDate.Value.Day >= first && e.ANEventInformations.FirstOrDefault().StartDate.Value.Day < last) .OrderByDescending(t => t.CreatedDate).ToList(); var anEventModels = new List <ANEventModel>(); foreach (var ev in events) { var model = new ANEventModel(); model.Id = ev.Id; model.Host = UserMapper.ToModel(ev.User); // get cover image var coverImageEntity = ev.ANEventImages.Where(x => x.ANEventImageType == (int)Common.ANEventImageType.ANEventCoverImage).OrderBy(x => x.SortPriority).FirstOrDefault(); if (coverImageEntity != null) { model.CoverPhoto = ImageMapper.ToModel(coverImageEntity.Image); } var information = ev.ANEventInformations.FirstOrDefault(); model.Information = ANEventInformationMapper.ToModel(information); if (model.Information != null) { model.Information.ANEventLocation = ANEventLocationMapper.ToModel(information.ANEventLocation); } model.CreatedDate = ev.CreatedDate; model.NumberOfMember = ev.ANEventMembers.Count; anEventModels.Add(model); } return(anEventModels); }
public ANEventDetailInformationModel GetEventDetailInformation(int Id) { //Thread.Sleep(3000); var entity = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include("ANEventInformations.ANEventLocation") .Include("User.UserProfiles.Image") .FirstOrDefault(x => x.Id == Id); if (entity == null) { return(null); } var firstInformation = entity.ANEventInformations.FirstOrDefault(); var firstUserProfile = entity.User.UserProfiles.FirstOrDefault(); var host = UserMapper.ToModel(entity.User); if (host != null) { if (firstUserProfile != null) { host.Profile = UserProfileMapper.ToModel(firstUserProfile); } if (firstUserProfile.Image != null) { host.Profile.Avatar = ImageMapper.ToModel(firstUserProfile.Image); } } var informationModel = new ANEventDetailInformationModel() { EventID = entity.Id, EventInformation = firstInformation != null? ANEventInformationMapper.ToModel(firstInformation) : null, Host = host }; if (informationModel.EventInformation != null) { informationModel.EventInformation.ANEventLocation = ANEventLocationMapper.ToModel(firstInformation.ANEventLocation); } return(informationModel); }
public List <ANEventModel> GetRelatedEvents(int eventId) { var hostId = this.ANDBUnitOfWork.ANEventRepository.GetAll().Where(x => x.Id == eventId).Select(x => x.UserId).FirstOrDefault().GetValueOrDefault(); if (hostId == 0) { return(null); } var events = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include(x => x.User) .Include(x => x.User.UserProfiles) .Include("User.UserProfiles.Image") .Include(x => x.ANEventImages) .Include("ANEventImages.Image") .Include("ANEventInformations.ANEventLocation") .Include(x => x.ANEventMembers) .Where(e => e.UserId.HasValue && e.UserId.Value == hostId && e.Id != eventId).OrderByDescending(t => t.CreatedDate).Take(3).ToList(); var anEventModels = new List <ANEventModel>(); foreach (var ev in events) { var model = new ANEventModel(); model.Id = ev.Id; model.Host = UserMapper.ToModel(ev.User); // get cover image var coverImageEntity = ev.ANEventImages.Where(x => x.ANEventImageType == (int)Common.ANEventImageType.ANEventCoverImage).OrderBy(x => x.SortPriority).FirstOrDefault(); if (coverImageEntity != null) { model.CoverPhoto = ImageMapper.ToModel(coverImageEntity.Image); } var information = ev.ANEventInformations.FirstOrDefault(); model.Information = ANEventInformationMapper.ToModel(information); if (model.Information != null) { model.Information.ANEventLocation = ANEventLocationMapper.ToModel(information.ANEventLocation); } model.CreatedDate = ev.CreatedDate; model.NumberOfMember = ev.ANEventMembers.Count; anEventModels.Add(model); } return(anEventModels); }
public UserProfileModel GetUserProfile(int Id) { var entity = this.ANDBUnitOfWork.UserProfileRepository.GetAll() .Include(x => x.Image) .FirstOrDefault(x => x.UserId.HasValue && x.UserId.Value == Id); if (entity == null) { return(null); } var model = UserProfileMapper.ToModel(entity); if (model != null) { model.Avatar = ImageMapper.ToModel(entity.Image); model.Gender.GenderName = entity.GenderId == (int)Common.GenderType.Male ? "Nam" : entity.GenderId == (int)Common.GenderType.Female ? "Nữ" : "Chưa xác định"; } return(model); }