public bool CreateANEvent(ANEventModel model) { var eEvent = new ANEvent(); eEvent.UserId = CurrentUser.Id; eEvent.CreatedDate = DateTime.Now; eEvent.UpdatedDate = DateTime.Now; var eInfo = new ANEventInformation(); eInfo.Title = model.Information.Title; eInfo.StartDate = model.Information.StartDate; eInfo.EndDate = model.Information.EndDate; eInfo.Description = model.Information.Description; eInfo.ShortDescription = model.Information.ShortDescription; var eLocation = new ANEventLocation(); eLocation.GGId = model.Information.ANEventLocation.GGId; eLocation.Address = model.Information.ANEventLocation.Address; eLocation.Name = model.Information.ANEventLocation.Name; eLocation.Lat = model.Information.ANEventLocation.Lat; eLocation.Lng = model.Information.ANEventLocation.Lng; var eCategories = model.Categories.Select(x => new Category() { Id = x.Id, Name = x.Name, Description = x.Description }).ToList(); eInfo.ANEventLocation = eLocation; eInfo.ANEvent = eEvent; eEvent.ANEventCategories = model.Categories.Select(x => new ANEventCategory() { CategoryId = x.Id }).ToList(); var elstInfo = new List <ANEventInformation>(); elstInfo.Add(eInfo); eEvent.ANEventInformations = elstInfo; //ANImage var eANEventImage = new ANEventImage() { ImageId = model.CoverPhoto.Id, ANEventImageType = (int)Common.ANEventImageType.ANEventCoverImage }; var lstANEventImage = new List <ANEventImage>(); lstANEventImage.Add(eANEventImage); eEvent.ANEventImages = lstANEventImage; this.ANDBUnitOfWork.ANEventRepository.Save(eEvent); this.ANDBUnitOfWork.Commit(); return(true); }
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> 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 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); }