internal static EventDetailsTDO GetProcessedPhotosReporting(Event ev, FotoShoutDbContext db) { EventDetailsTDO evDetails = new EventDetailsTDO(); IEnumerable <Photo> photos = ev.Photos.Where(p => p.Status > (byte)PhotoStatus.Selected).OrderBy(p => p.Filename); if (!photos.Any()) { return(evDetails); } HashSet <dynamic> photosDetails = new HashSet <dynamic>(); foreach (var photo in photos) { dynamic tdo = new ExpandoObject(); tdo.PhotoId = photo.PhotoId; tdo.Filename = photo.Filename; tdo.Guests = PhotoAnnotationService.GetGuestsInfo(photo, false); photosDetails.Add(tdo); } if (photosDetails.Any()) { evDetails.EventOption = ev.EventOption; evDetails.PhotosDetails = photosDetails; } return(evDetails); }
// id to Guid private static Guest GetGuestById(int evId, Guid id, FotoShoutDbContext db) { var ev = db.Events.Find(evId); if (ev != null) { return(ev.Guests.Where(g => g.GuestId == id).SingleOrDefault()); } return(null); }
private static Guest GetGuestByEmail(int evId, string email, FotoShoutDbContext db) { if (string.IsNullOrEmpty(email)) { return(null); } var ev = db.Events.Find(evId); if (ev != null) { return(ev.Guests.Where(g => g.Email != null && email.Equals(g.Email, StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault()); } return(null); }
internal static IEnumerable <PhotoTDO> GetPublishAuthorizedPhotos(Event ev, FotoShoutDbContext db) { IEnumerable <Photo> photos = ev.Photos.Where(p => (p.Status == (byte)PhotoStatus.Submitted)); HashSet <PhotoTDO> authorizedPhotos = new HashSet <PhotoTDO>(); foreach (Photo photo in photos) { GuestPhoto gp = photo.GuestPhotos.Where(g => g.AuthorizePublish == false).FirstOrDefault(); if (gp == null) { authorizedPhotos.Add(EventPhotosService.GenerateTDO(ev, photo)); } } return(authorizedPhotos); }
internal static IEnumerable <PhotoTDO> GetUnauthorizedPhotos(Event ev, FotoShoutDbContext db) { IEnumerable <Photo> photos = ev.Photos.Where(p => (p.Status == (byte)PhotoStatus.Submitted)); HashSet <PhotoTDO> unauthorizedPhotos = new HashSet <PhotoTDO>(); foreach (Photo photo in photos) { IEnumerable <GuestPhoto> gps = photo.GuestPhotos.Where(g => g.AuthorizePublish == false); if (gps != null && gps.Any()) { unauthorizedPhotos.Add(EventPhotosService.GenerateTDO(ev, photo)); } } return(unauthorizedPhotos); }
// id to Guid internal static byte[] GetSignatureById(int id, Guid guestId, FotoShoutDbContext db) { Event ev = db.Events.Find(id); if (ev == null) { throw new PhotoAnnotationException(string.Format("Event {0} not found.", id)); } Guest guest = ev.Guests.Where(g => g.GuestId == guestId).SingleOrDefault(); if (guest == null) { throw new PhotoAnnotationException(string.Format("Guest {0} not found in the {1} event.", guestId, id)); } return(guest.Signature); }
internal static GuestTDO GetGuestTDOByEmail(int id, string email, FotoShoutDbContext db) { Event ev = db.Events.Find(id); if (ev == null) { return(null); } Guest guest = ev.Guests.Where(g => g.Email != null && g.Email.Equals(email, StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault(); if (guest == null) { return(null); } return(GenerateTDO(guest, ev.EventOption)); }
// id to Guid internal static GuestTDO GetGuestTDOById(int id, Guid guestId, FotoShoutDbContext db) { Event ev = db.Events.Find(id); if (ev == null) { return(null); } Guest guest = ev.Guests.Where(g => g.GuestId == guestId).SingleOrDefault(); if (guest == null) { return(null); } return(GenerateTDO(guest, ev.EventOption)); }
protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); if (Request.RequestUri.AbsolutePath.ToLower().Contains(Constants.FS_API_PREFIX)) { try { // get the api key string apiKey = this.GetApiKey(_logger); // validate the key AuthorizationKey = new Guid(apiKey); FotoShoutUtils.Log.LogManager.Info(_logger, "Getting account info..."); using (var db = new FotoShoutDbContext()) { CurrentUser = this.GetUser(apiKey, db); if (CurrentUser == null) { this.GenerateException(HttpStatusCode.Unauthorized, Errors.ERROR_LOGIN_NOACCOUNT, _logger); } Account account = this.GetAccount(CurrentUser.Id, db); if (account == null) { this.GenerateException(HttpStatusCode.Unauthorized, Errors.ERROR_AUTHORIZATIONKEY_INVALID, _logger); } AccountName = account.AccountName; } FotoShoutUtils.Log.LogManager.Info(_logger, "Successully got account info"); Uri uri = controllerContext.Request.RequestUri; AppConfigs.VirtualRoot = uri.Scheme + Uri.SchemeDelimiter + uri.Host + "/"; } catch (HttpResponseException ex) { throw ex; } catch (Exception ex) { FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString()); this.GenerateException(HttpStatusCode.BadRequest, ex.Message); } } }
internal static bool ClearEventRelationships(Event ev, FotoShoutDbContext db) { try { // Remove all photos that are associated to the event foreach (Photo p in ev.Photos) { db.Photos.Remove(p); } // Clear all associations to sponsors ev.Sponsors.Clear(); return(true); } catch (Exception ex) { FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString()); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { ReasonPhrase = ex.Message, Content = new StringContent(ex.Message) }); } }
internal static IEnumerable <GuestTDO> GetGuestTDOs(int id, FotoShoutDbContext db) { Event ev = db.Events.Find(id); if (ev == null) { return(null); } IEnumerable <Guest> gs = ev.Guests.OrderBy(g => g.LastName); HashSet <GuestTDO> tdos = new HashSet <GuestTDO>(); if (gs.Any()) { foreach (Guest g in gs) { GuestTDO tdo = GenerateTDO(g, ev.EventOption); tdos.Add(tdo); } } return(tdos); }
internal static IEnumerable <PhotoGroupTDO> GetProcessedPhotoGroupsByDate(Event ev, FotoShoutDbContext db) { IEnumerable <IGrouping <string, Photo> > photoGroups = ev.Photos.Where(p => (p.Status == (byte)PhotoStatus.Submitted || p.Status == (byte)PhotoStatus.PendingPublish || p.Status == (byte)PhotoStatus.Published)).GroupBy(p => p.Created.ToShortDateString()); HashSet <PhotoGroupTDO> tdos = new HashSet <PhotoGroupTDO>(); if (!photoGroups.Any()) { return(tdos); } foreach (IGrouping <string, Photo> photoGroup in photoGroups) { if (photoGroup.Any()) { PhotoGroupTDO tdo = new PhotoGroupTDO { Created = DateTime.Parse(photoGroup.Key), NumPhotos = photoGroup.Count(), Thumbnail = AppConfigs.VirtualRoot + photoGroup.FirstOrDefault().Thumbnail }; tdos.Add(tdo); } } return(tdos.OrderByDescending(tdo => tdo.Created)); }
internal static IEnumerable <PhotoDetailsTDO> GetProcessedPhotosDetailing(Event ev, string created, int page, int pageSize, FotoShoutDbContext db) { Func <Photo, Boolean> func; if (string.IsNullOrEmpty(created)) { func = p => (p.Status == (byte)PhotoStatus.Submitted || p.Status == (byte)PhotoStatus.PendingPublish || p.Status == (byte)PhotoStatus.Published); } else { created = DateTime.Parse(created).ToShortDateString(); func = p => (p.Created.ToShortDateString().Equals(created, StringComparison.InvariantCultureIgnoreCase) && (p.Status == (byte)PhotoStatus.Submitted || p.Status == (byte)PhotoStatus.PendingPublish || p.Status == (byte)PhotoStatus.Published)); } IEnumerable <Photo> photos = ev.Photos.Where(func).OrderBy(p => p.Filename); if (page > 0 && pageSize > 0 && (photos.Count() > pageSize)) { photos = photos.Skip((page - 1) * pageSize).Take(pageSize); } IEnumerable <PhotoDetailsTDO> photosDetails = (from p in photos join e in db.EventBroadcasts on p.PhotoId equals e.PhotoId into pe from subset in pe.DefaultIfEmpty() select new PhotoDetailsTDO { PhotoId = p.PhotoId, Filename = p.Filename, Status = p.Status, Submitted = p.Submitted, SubmittedBy = p.SubmittedBy, Thumbnail = string.IsNullOrEmpty(p.Thumbnail) ? "" : AppConfigs.VirtualRoot + p.Thumbnail, Error = p.Error, Thumbnails = (subset == null) ? string.Empty : subset.Thumbnails, PermaLinks = (subset == null) ? string.Empty : subset.PermaLinks }).ToList(); if (!photosDetails.Any()) { return(photosDetails); } foreach (Photo photo in photos) { PhotoDetailsTDO tdo = photosDetails.Where(p => p.PhotoId == photo.PhotoId).Single(); tdo.Guests = PhotoAnnotationService.GetGuestTDOs(photo, true); } return(photosDetails); }
public static Account GetAccount(this ApiController controller, int userId, FotoShoutDbContext db) { return((from u in db.Users join a in db.Accounts on u.Account.Id equals a.Id where u.Id == userId select a).SingleOrDefault()); }
internal static IEnumerable <IGrouping <Guid, PhotoGuest> > GetPhotoEmailsGroupByPhoto(IEnumerable <Guid> photoIds, FotoShoutDbContext db) { return((IEnumerable <IGrouping <Guid, PhotoGuest> >)db.PhotoEmails.Where <PhotoEmail>(pe => photoIds.Contains <Guid>(pe.PhotoId)).Select <PhotoEmail, PhotoGuest>(pe => new PhotoGuest { PhotoId = pe.PhotoId, GuestId = pe.GuestId }).GroupBy <PhotoGuest, Guid>(pe => pe.PhotoId)); }
internal static IEnumerable <PhotoTDO> GetPublishedPhotosByGuest(Event ev, string name, FotoShoutDbContext db) { return(GetPhotosByGuest(ev, name, PhotoStatus.Published, 0, 0, db)); }
internal static bool ReannotatePhoto(Photo photo, PhotoAnnotation photoAnnotation, FotoShoutDbContext db) { Event ev = photo.Event; ICollection <GuestTDO> tdos = photoAnnotation.Guests; if (tdos == null || tdos.Count == 0) { if (photo.GuestPhotos.Any()) { while (photo.GuestPhotos.Any()) { db.GuestPhotos.Remove(photo.GuestPhotos.FirstOrDefault()); } ClearAllGuests(photo); } photo.Rating = photoAnnotation.Rating; photo.Status = (byte)PhotoStatus.Unselected; photo.Submitted = null; photo.SubmittedBy = 0; photo.Error = ""; } else { ICollection <GuestPhoto> gps = photo.GuestPhotos; HashSet <GuestPhoto> removedGuests = new HashSet <GuestPhoto>(); foreach (GuestPhoto gp in gps) { GuestTDO tdo = null; if (string.IsNullOrEmpty(gp.Guest.Email)) { tdo = tdos.Where(t => t.GuestId == gp.Guest.GuestId).SingleOrDefault(); } else { tdo = tdos.Where(t => t.GuestId == gp.Guest.GuestId || (!string.IsNullOrEmpty(t.Email) && t.Email.Equals(gp.Guest.Email, StringComparison.InvariantCultureIgnoreCase))).SingleOrDefault(); } if (tdo == null) { removedGuests.Add(gp); } } foreach (GuestPhoto removedGuest in removedGuests) { gps.Remove(removedGuest); db.GuestPhotos.Remove(removedGuest); } if (!AnnotatePhoto(photo, photoAnnotation, db)) { return(false); } } return(true); }
internal static bool AnnotatePhoto(Photo photo, PhotoAnnotation photoAnnotation, FotoShoutDbContext db) { // Updating photo rating photo.Rating = photoAnnotation.Rating; // Adding the list of guests to the photo Event ev = photo.Event; ICollection <GuestPhoto> gps = photo.GuestPhotos; ICollection <GuestTDO> tdos = photoAnnotation.Guests; foreach (GuestTDO tdo in tdos) { Guest guest = !string.IsNullOrEmpty(tdo.Email) ? GetGuestByEmail(ev.EventId, tdo.Email, db) : GetGuestById(ev.EventId, tdo.GuestId, db); if (guest == null) { guest = PhotoAnnotationService.GenerateGuest(tdo, photo.Event.EventOption); ev.Guests.Add(guest); } else { PhotoAnnotationService.UpdateGuest(guest, tdo, photo.Event.EventOption); } GuestPhoto guestPhoto = gps.Where(gp => gp.Guest.GuestId == guest.GuestId).SingleOrDefault(); if (guestPhoto == null) { guestPhoto = new GuestPhoto { Id = Guid.NewGuid(), Event_EventId = photo.Event.EventId, Photo = photo, Guest = guest, AuthorizePublish = tdo.AuthorizePublish }; gps.Add(guestPhoto); } else { guestPhoto.AuthorizePublish = tdo.AuthorizePublish; } } photo.Error = ""; photo.Status = (byte)PhotoStatus.Submitted; return(true); }
internal static string GetThumbnailUrl(int eventId, string physicalPath, string virtualPath, FotoShoutDbContext db) { // Getting the list of photos' extensions string imageExts = EventPhotosService.GetImageExts(); // Get the first photo that belongs to the event's folder string filename = PagingFileUtils.GetFirstFileName(physicalPath, imageExts); if (!string.IsNullOrEmpty(filename)) { string folder = physicalPath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? physicalPath : (physicalPath + Path.DirectorySeparatorChar); DirectoryInfo dirInfo = FotoShoutUtils.Utils.IO.DirectoryUtils.CreateSubFolder(folder, Constants.STR_THUMB); bool succeeded = (dirInfo != null) ? ImageUtils.CreateThumbnailFileIfAny(folder + filename, GetThumbnailPath(folder, filename)) : false; if (succeeded) { return(GetThumbnailVirtualPath(virtualPath, filename)); } } return(""); }
private static IEnumerable <PhotoTDO> GetPhotosByGuest(Event ev, string name, PhotoStatus status, int page, int pageSize, FotoShoutDbContext db) { IEnumerable <Guest> guests = ev.Guests.Where(g => (g.FirstName + " " + g.LastName + " " + g.MiddleInitial).Contains(name, StringComparison.InvariantCultureIgnoreCase)); HashSet <PhotoTDO> photos = new HashSet <PhotoTDO>(); foreach (Guest guest in guests) { IEnumerable <PhotoTDO> ps = guest.GuestPhotos.Where(gp => gp.Photo.Event.EventId == ev.EventId && gp.Photo.Status == (byte)status).Select(gp => new PhotoTDO { PhotoId = gp.Photo.PhotoId, Filename = gp.Photo.Filename, Folder = gp.Photo.Folder, Status = gp.Photo.Status, Submitted = gp.Photo.Submitted, SubmittedBy = gp.Photo.SubmittedBy, Thumbnail = AppConfigs.VirtualRoot + gp.Photo.Thumbnail, Created = gp.Photo.Created, Image = AppConfigs.VirtualRoot + ev.EventVirtualPath + "/" + Constants.STR_PROCESSED + "/" + gp.Photo.Filename, Rating = gp.Photo.Rating }); photos.UnionWith(ps); } return((page > 0 && pageSize > 0 && (photos.Count() > pageSize)) ? photos.Distinct(new PhotoComparer <PhotoTDO>()).Skip((page - 1) * pageSize).Take(pageSize) : photos.Distinct(new PhotoComparer <PhotoTDO>())); }
internal static IEnumerable <PhotoTDO> GetProcessedPhotosByGuest(Event ev, string name, string created, int page, int pageSize, FotoShoutDbContext db) { Func <GuestPhoto, Boolean> func; if (string.IsNullOrEmpty(created)) { func = gp => (gp.Photo.Event.EventId == ev.EventId) && (gp.Photo.Status == (byte)PhotoStatus.Submitted || gp.Photo.Status == (byte)PhotoStatus.PendingPublish || gp.Photo.Status == (byte)PhotoStatus.Published); } else { created = DateTime.Parse(created).ToShortDateString(); func = gp => (gp.Photo.Event.EventId == ev.EventId) && gp.Photo.Created.ToShortDateString().Equals(created, StringComparison.InvariantCultureIgnoreCase) && (gp.Photo.Status == (byte)PhotoStatus.Submitted || gp.Photo.Status == (byte)PhotoStatus.PendingPublish || gp.Photo.Status == (byte)PhotoStatus.Published); } IEnumerable <Guest> guests = ev.Guests.Where(g => (g.FirstName + " " + g.LastName + " " + g.MiddleInitial).Contains(name, StringComparison.InvariantCultureIgnoreCase)); HashSet <PhotoTDO> photos = new HashSet <PhotoTDO>(); foreach (Guest guest in guests) { IEnumerable <PhotoTDO> ps = guest.GuestPhotos.Where(func).Select(gp => new PhotoTDO { PhotoId = gp.Photo.PhotoId, Filename = gp.Photo.Filename, Folder = gp.Photo.Folder, Status = gp.Photo.Status, Submitted = gp.Photo.Submitted, SubmittedBy = gp.Photo.SubmittedBy, Thumbnail = AppConfigs.VirtualRoot + gp.Photo.Thumbnail, Created = gp.Photo.Created, Image = AppConfigs.VirtualRoot + ev.EventVirtualPath + "/" + Constants.STR_PROCESSED + "/" + gp.Photo.Filename, Rating = gp.Photo.Rating }); if (ps.Any()) { photos.UnionWith(ps); } } IEnumerable <PhotoTDO> ret = (page > 0 && pageSize > 0 && (photos.Count() > pageSize)) ? photos.Distinct(new PhotoComparer <PhotoTDO>()).OrderBy(p => p.Created).Skip((page - 1) * pageSize).Take(pageSize) : photos.Distinct(new PhotoComparer <PhotoTDO>()).OrderBy(p => p.Created); return(ret); }
internal static Event GetEvent(int id, int userId, HttpRequestMessage request, FotoShoutDbContext db, bool isIncludingPhotos = true, bool isIncludingGuests = false) { Event ev = null; try { if (isIncludingPhotos && isIncludingGuests) { ev = db.Events.Where(e => e.EventId == id && e.User.Id == userId).Include(e => e.Photos).Include(e => e.Guests).Include(e => e.EventOption).Include(e => e.EmailTemplate).SingleOrDefault(); } else if (isIncludingPhotos) { ev = db.Events.Where(e => e.EventId == id && e.User.Id == userId).Include(e => e.Photos).Include(e => e.EventOption).Include(e => e.EmailTemplate).SingleOrDefault(); } else { ev = db.Events.Where(e => e.EventId == id && e.User.Id == userId).Include(e => e.EventOption).Include(e => e.EmailTemplate).SingleOrDefault(); } } catch (Exception ex) { throw new HttpResponseException(request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } if (ev == null) { throw new HttpResponseException(request.CreateResponse(HttpStatusCode.NotFound, string.Format(Errors.ERROR_EVENT_NOTFOUND, id))); } return(ev); }
private static IEnumerable <PhotoTDO> GetPhotos(Event ev, PhotoStatus status, int page, int pageSize, FotoShoutDbContext db) { IEnumerable <PhotoTDO> photos = ev.Photos.Where(p => p.Status == (byte)status).Select(p => new PhotoTDO { PhotoId = p.PhotoId, Filename = p.Filename, Folder = p.Folder, Status = p.Status, Submitted = p.Submitted, SubmittedBy = p.SubmittedBy, Thumbnail = AppConfigs.VirtualRoot + p.Thumbnail, Created = p.Created, Image = AppConfigs.VirtualRoot + ev.EventVirtualPath + "/" + Constants.STR_PROCESSED + "/" + p.Filename, Rating = p.Rating }); if (page > 0 && pageSize > 0 && (photos.Count() > pageSize)) { return(photos.Skip((page - 1) * pageSize).Take(pageSize)); } return(photos); }
internal static IEnumerable <PhotoTDO> GetPublishedPhotos(Event ev, FotoShoutDbContext db) { return(GetPhotos(ev, PhotoStatus.Published, 0, 0, db)); }
internal static IEnumerable <EventBroadcast> GetBroadcasts(Event ev, FotoShoutDbContext db) { return(db.EventBroadcasts.Where(eb => eb.EventId == ev.EventId && (eb.Status == (byte)EventBroadcastStatus.Pending || eb.Status == (byte)EventBroadcastStatus.PublishPending))); }
internal static IEnumerable <PhotoTDO> GetProcessedPhotos(Event ev, string created, int page, int pageSize, FotoShoutDbContext db) { Func <Photo, Boolean> func; if (string.IsNullOrEmpty(created)) { func = p => (p.Status == (byte)PhotoStatus.Submitted || p.Status == (byte)PhotoStatus.PendingPublish || p.Status == (byte)PhotoStatus.Published); } else { created = DateTime.Parse(created).ToShortDateString(); func = p => (p.Created.ToShortDateString().Equals(created, StringComparison.InvariantCultureIgnoreCase) && (p.Status == (byte)PhotoStatus.Submitted || p.Status == (byte)PhotoStatus.PendingPublish || p.Status == (byte)PhotoStatus.Published)); } IEnumerable <Photo> photos = ev.Photos.Where(func).OrderBy(p => p.Created); if (page > 0 && pageSize > 0 && (photos.Count() > pageSize)) { photos = photos.Skip((page - 1) * pageSize).Take(pageSize); } HashSet <PhotoTDO> tdos = new HashSet <PhotoTDO>(); if (!photos.Any()) { return(tdos); } foreach (Photo photo in photos) { PhotoTDO tdo = EventPhotosService.GenerateTDO(ev, photo); tdo.Guests = PhotoAnnotationService.GetGuestTDOs(photo, true); tdos.Add(tdo); } return(tdos); }
internal static IEnumerable <PhotoEmail> GetPhotoEmails(Photo photo, FotoShoutDbContext db) { return((IEnumerable <PhotoEmail>)db.PhotoEmails.Where <PhotoEmail>(pe => pe.PhotoId == photo.PhotoId)); }
public static User GetUser(this ApiController controller, string apiKey, FotoShoutDbContext db) { return((from u in db.Users join ua in db.UserAuthorizations on u.Authorization.Id equals ua.Id where ua.AuthorizationKey == new Guid(apiKey) select u).SingleOrDefault()); }