public bool AddPhoto(Photo photo, Logger logger) { bool result = false; try { using (var db = new PhotoBoothContext()) { if (photo.Created == DateTime.MinValue) { photo.Created = DateTime.Now; } db.Photos.Add(photo); db.SaveChanges(); } result = true; //logger.Info("Record for file {0} created", photo.LocalPathToImage); } catch (Exception ex) { logger.Error("Record for file {0} NOT created!", photo.LocalPathToImage); logger.Error(ex); if (ex.InnerException != null) { logger.Error(ex.InnerException); if (ex.InnerException.InnerException != null) { logger.Error(ex.InnerException.InnerException); } } } return(result); }
public bool SetBoothAvailable() { bool result = false; try { if (IsDatabaseConnectionExist()) { using (var db = new PhotoBoothContext()) { var currentPhotoBooth = db.PhotoBooths.FirstOrDefault(pb => pb.Id == _boothGuid); if (currentPhotoBooth != null) { currentPhotoBooth.LastAvailableDate = DateTime.Now; } db.SaveChanges(); result = true; LogManager.GetLogger("BoothAvailabilityLogger").Info("Availability time updated"); } } } catch (Exception ex) { LogManager.GetLogger("BoothAvailabilityLogger").Error(ex); } return(result); }
public List <PhotoEvent> FetchCurrentBoothEvents() { List <PhotoEvent> currentBoothEvents; using (PhotoBoothContext context = new PhotoBoothContext()) { currentBoothEvents = context.PhotoEvents.Where(e => e.PhotoBoothEntityId == _boothGuid && e.StartDateTime > DateTime.Now).ToList(); } return(currentBoothEvents); }
public bool IsDatabaseConnectionExist() { using (var db = new PhotoBoothContext()) { DbConnection conn = db.Database.Connection; try { conn.Open(); return(true); } catch { return(false); } } }
public PhotoEvent GetCurrentEvent() { PhotoEvent currentBoothEventNow = null; try { using (var db = new PhotoBoothContext()) { IQueryable <PhotoEvent> currentBoothEvents = db.PhotoEvents.Where(pe => pe.PhotoBoothEntityId == _boothGuid); foreach (var currentBoothEvent in currentBoothEvents) { if (currentBoothEvent.StartDateTime <= DateTime.Now && currentBoothEvent.EndDateTime >= DateTime.Now) { currentBoothEventNow = currentBoothEvent; break; } } } } catch (Exception ex) { LogManager.GetLogger("firstTaskFile").Error(ex); } //if (currentBoothEventNow != null) //{ // logger.Info("Event {0} right now!", currentBoothEventNow.Id); // Settings.CurrentEvent = currentBoothEventNow; // Settings.LastEvent = currentBoothEventNow; // EventInfo eventInfo = new EventInfo() // { // Id = currentBoothEventNow.Id, // StartDate = currentBoothEventNow.StartDateTime, // EndDate = currentBoothEventNow.EndDateTime // }; // WriteEventToFile(eventInfo); //} //else //{ // logger.Info("No new events..."); // Settings.CurrentEvent = null; //} return(currentBoothEventNow); }
public bool IsPhotoRecordExist(string filePath, Logger logger) { string md5 = FilesHelper.Instance.CalculateMd5(filePath); Photo photo = null; try { using (var db = new PhotoBoothContext()) { photo = db.Photos.FirstOrDefault(p => p.Md5Hash == md5); } } catch (Exception ex) { logger.Error(ex); } return(photo != null); }
public void RemovePrintQueueElement(PrintQueue photoBoothPrintElement) { if (IsDatabaseConnectionExist()) { using (var db = new PhotoBoothContext()) { try { PrintQueue objectToDelete = db.PrintQueue.FirstOrDefault(p => p.BlobPathToImage == photoBoothPrintElement.BlobPathToImage); db.PrintQueue.Remove(objectToDelete); db.SaveChanges(); } catch (Exception ex) { LogManager.GetLogger("PrintTask").Error(ex); } } } }
public List <PrintQueue> GetCurrentBoothPrintPhotos() { List <PrintQueue> currentPhotoBoothPrintElements = null; try { if (IsDatabaseConnectionExist()) { using (var db = new PhotoBoothContext()) { currentPhotoBoothPrintElements = db.PrintQueue.Where(p => p.PhotoBoothEntityId == _boothGuid).ToList(); } } } catch (Exception ex) { LogManager.GetLogger("BoothAvailabilityTask").Error(ex); } return(currentPhotoBoothPrintElements); }
public bool IsDatabaseConnectionExist() { bool result = false; using (var db = new PhotoBoothContext()) { DbConnection conn = db.Database.Connection; try { conn.Open(); result = true; } catch { result = false; } } //LogManager.GetLogger("firstTaskFile").Info("IsDatabaseConnectionExist: {0}", result); return(result); }
public PhotoEvent GetCurrentEvent(Logger logger) { PhotoEvent currentBoothEventNow = null; try { using (var db = new PhotoBoothContext()) { IQueryable <PhotoEvent> currentBoothEvents = db.PhotoEvents.Where(pe => pe.PhotoBoothEntityId == _boothGuid); foreach (var currentBoothEvent in currentBoothEvents) { if (currentBoothEvent.StartDateTime <= DateTime.Now && currentBoothEvent.EndDateTime >= DateTime.Now) { currentBoothEventNow = currentBoothEvent; break; } } } } catch (Exception ex) { logger.Error(ex); } if (currentBoothEventNow != null) { logger.Info("Event {0} right now!", currentBoothEventNow.Id); Settings.CurrentEvent = currentBoothEventNow; Settings.LastEvent = currentBoothEventNow; } else { logger.Info("No new events..."); Settings.CurrentEvent = null; } return(currentBoothEventNow); }
public void Configuration(IAppBuilder app) { this.ConfigureAuth(app); using (var context = new PhotoBoothContext()) { } using (var context = new ApplicationDbContext()) { var roleStore = new RoleStore <IdentityRole>(context); var roleManager = new RoleManager <IdentityRole>(roleStore); roleManager.Create(new IdentityRole("Admin")); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); var adminEmail = ConfigurationManager.AppSettings.Get("AdminEmail"); if (adminEmail != null) { var user = userManager.FindByEmail(adminEmail); if (user == null) { user = new ApplicationUser { UserName = adminEmail, Email = adminEmail }; var result = userManager.Create(user, adminEmail); if (result.Succeeded) { userManager.AddToRole(user.Id, "Admin"); context.SaveChanges(); } } } } }