private static ScanSession CreateScanSessionEntryPrivate(TenantUserSession tenantUserSession, string name, string description, ContextTenant context) { if (context == null) { throw (new ArgumentNullException("context")); } if (string.IsNullOrEmpty(name.Trim())) { throw (new Exception("Name is required")); } if (context.ScanSessions.Any(x => x.Name.ToLower().Trim() == name.ToLower().Trim())) { throw new Exception("Scan Session with same name already exists. Please select a unique name."); } ScanSession scanSession = new ScanSession(); scanSession.DateTimeCreated = DateTime.UtcNow; scanSession.Description = description; scanSession.Guid = Guid.NewGuid(); scanSession.Name = name; scanSession.UserId = tenantUserSession.User.Id; var scan = context.ScanSessions.Add(scanSession); context.SaveChanges(); return(scan); }
public static bool Document(TenantUserSession tenantUserSession, Document document, out Exception exception, bool ForceACLExceptionHandler = false) { exception = null; bool result = false; try { if (document == null) { throw (new Exception("Requested document was not found")); } using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { var userDocuments = context.UserDocuments.Where(u => u.UserId == tenantUserSession.User.Id).ToList(); if (!(userDocuments.Any(ud => ud.DocumentId == document.Id))) { throw (new Exception("You aren not authorized to access the document")); } result = true; } } catch (Exception ex) { exception = ex; if (ForceACLExceptionHandler) { } } return(result); }
public static bool AddDepartment(TenantUserSession tenantUserSession, string departmentName, out Department department, out Exception exception) { exception = null; department = null; bool result = false; try { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { using (var contextTrans = context.Database.BeginTransaction()) { var departmentExist = context.Departments.Where(x => x.Name == departmentName).SingleOrDefault(); if (departmentExist != null) { throw (new Exception("Department already exists")); } Department _department = new Department(); _department.Name = departmentName; department = context.Departments.Add(_department); context.SaveChanges(); result = true; contextTrans.Commit(); } } } catch (Exception ex) { exception = ex; } return(result); }
public static bool GetPublicKey(TenantUserSession tenantUserSession, long tenandId, out string keyPublic, out Exception exception) { var result = false; keyPublic = ""; exception = null; try { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { var tenant = context.Tenants.SingleOrDefault(t => (t.Id == tenandId)); if (tenant == null) { throw (new RowNotFoundException()); } else { keyPublic = tenant.RsaKeyPublic; result = true; } } } catch (Exception e) { exception = e; } return(result); }
public static bool ValidateToken ( string token, SessionType sessionType, string domain, string username, string clientIpAddress, string userAgent, long ticks, string sessionId, out TenantUserSession tenantUserSession, out Exception exception ) { var result = false; exception = null; tenantUserSession = null; try { AuthenticationManagement.ThrowOnInvalidToken(token, sessionType, domain, username, clientIpAddress, userAgent, ticks, sessionId, out tenantUserSession); result = true; } catch (Exception e) { exception = e; } return(result); }
public static bool UpdateVendor(TenantUserSession tenantUserSession, Vendor vendor, out Exception exception) { exception = null; bool result = false; try { ContextTenant context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString); Vendor temp = context.Vendors.Where(x => x.Id == vendor.Id).Select(x => x).FirstOrDefault(); temp.VendorName = vendor.VendorName; temp.Gst = vendor.Gst; temp.Address = vendor.Address; temp.Phone = vendor.Phone; temp.Email = vendor.Email; temp.ContactPerson = vendor.ContactPerson; context.Vendors.Add(temp); context.Entry(temp).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); result = true; } catch (Exception ex) { exception = ex; result = false; } return(result); }
public static ICollection <Button> GetAvailableScreenButtons(TenantUserSession tenantUserSession, int UserId, int ScreenId) { List <Button> buttons = new List <Button>(); List <UserRole> userRoles = new List <UserRole>(); using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { var query = from ur in context.UserRoles join rr in context.RoleRights on ur.RoleId equals rr.RoleId where ur.UserId == UserId && rr.Screen.Id == ScreenId select new { buttonId = rr.Button.Id }; foreach (var button in query) { buttons.Add(context.Buttons.Where(b => b.Id == button.buttonId).First()); } } return(buttons); }
public static ICollection <Screen> GetAvailableMenus(TenantUserSession tenantUserSession, int UserId) { List <Screen> screens = new List <Screen>(); List <UserRole> userRoles = new List <UserRole>(); using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { var query = from ur in context.UserRoles join rr in context.RoleRights on ur.RoleId equals rr.RoleId where ur.UserId == UserId select new { screenId = rr.Screen.Id }; foreach (var screen in query) { screens.Add(context.Screens.Where(b => b.Id == screen.screenId).First()); } } return(screens); }
public static int AddTenant(TenantUserSession tenantUserSession, Tenant tenant) { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { tenant = context.Tenants.Add(tenant); context.SaveChanges(); } return(Convert.ToInt32(tenant.Id)); }
public static int UpdateTenant(TenantUserSession tenantUserSession, Tenant tenant) { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { var tempTenant = new Tenant(); tempTenant = context.Tenants.FirstOrDefault(t => t.Id == tenant.Id); tempTenant.CompanyName = tenant.CompanyName; tempTenant.Domain = tenant.Domain; tempTenant.ContactOwnerNameGiven = tenant.ContactOwnerNameGiven; tempTenant.ContactOwnerNameFamily = tenant.ContactOwnerNameFamily; tempTenant.ContactOwnerAddress = tenant.ContactOwnerAddress; tempTenant.ContactOwnerCity = tenant.ContactOwnerCity; tempTenant.ContactOwnerState = tenant.ContactOwnerState; tempTenant.ContactOwnerZipCode = tenant.ContactOwnerZipCode; tempTenant.ContactOwnerCountry = tenant.ContactOwnerCountry; tempTenant.ContactOwnerPhone = tenant.ContactOwnerPhone; tempTenant.ContactOwnerFax = tenant.ContactOwnerFax; tempTenant.ContactOwnerEmail = tenant.ContactOwnerEmail; tempTenant.ContactAdministratorNameGiven = tenant.ContactAdministratorNameGiven; tempTenant.ContactAdministratorNameFamily = tenant.ContactAdministratorNameFamily; tempTenant.ContactAdministratorAddress = tenant.ContactAdministratorAddress; tempTenant.ContactAdministratorCity = tenant.ContactAdministratorCity; tempTenant.ContactAdministratorState = tenant.ContactAdministratorState; tempTenant.ContactAdministratorZipCode = tenant.ContactAdministratorZipCode; tempTenant.ContactAdministratorCountry = tenant.ContactAdministratorCountry; tempTenant.ContactAdministratorPhone = tenant.ContactAdministratorPhone; tempTenant.ContactAdministratorFax = tenant.ContactAdministratorFax; tempTenant.ContactAdministratorEmail = tenant.ContactAdministratorEmail; tempTenant.ContactBillingNameGiven = tenant.ContactBillingNameGiven; tempTenant.ContactBillingNameFamily = tenant.ContactBillingNameFamily; tempTenant.ContactBillingAddress = tenant.ContactBillingAddress; tempTenant.ContactBillingCity = tenant.ContactBillingCity; tempTenant.ContactBillingState = tenant.ContactBillingState; tempTenant.ContactBillingZipCode = tenant.ContactBillingZipCode; tempTenant.ContactBillingCountry = tenant.ContactBillingCountry; tempTenant.ContactBillingPhone = tenant.ContactBillingPhone; tempTenant.ContactBillingFax = tenant.ContactBillingFax; tempTenant.ContactBillingEmail = tenant.ContactBillingEmail; tempTenant.ContactTechnicalNameGiven = tenant.ContactTechnicalNameGiven; tempTenant.ContactTechnicalNameFamily = tenant.ContactTechnicalNameFamily; tempTenant.ContactTechnicalAddress = tenant.ContactTechnicalAddress; tempTenant.ContactTechnicalCity = tenant.ContactTechnicalCity; tempTenant.ContactTechnicalState = tenant.ContactTechnicalState; tempTenant.ContactTechnicalZipCode = tenant.ContactTechnicalZipCode; tempTenant.ContactTechnicalCountry = tenant.ContactTechnicalCountry; tempTenant.ContactTechnicalPhone = tenant.ContactTechnicalPhone; tempTenant.ContactTechnicalFax = tenant.ContactTechnicalFax; tempTenant.ContactTechnicalEmail = tenant.ContactTechnicalEmail; context.Tenants.Attach(tempTenant); context.Entry(tempTenant).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(Convert.ToInt32(tenant.Id)); }
public static TenantSubscription GetSubscriptionByTenantId(TenantUserSession tenantUserSession, int id) { TenantSubscription subscription = null; using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { subscription = context.TenantSubscriptions.Where(r => r.TenantId == id && r.IsActive == true).FirstOrDefault(); } return(subscription); }
public static IList <Subscription> GetSubscriptions(TenantUserSession tenantUserSession) { IList <Subscription> list = new List <Subscription>(); using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { list = context.Subscriptions.ToList(); } return(list); }
public static IList <Tenant> GetTenants(TenantUserSession tenantUserSession) { IList <Tenant> list = new List <Tenant>(); using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { list = context.Tenants.ToList(); } return(list); }
public static Tenant GetTenantInfo(TenantUserSession tenantUserSession, int id) { Tenant Tenant = null; using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { Tenant = context.Tenants.Where(r => r.Id == id).FirstOrDefault(); } return(Tenant); }
public static IList <TenantSubscription> GetPreviousSubscriptions(TenantUserSession tenantUserSession, int tenantId) { var list = new List <TenantSubscription>(); using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { list = context.TenantSubscriptions.Where(t => ((t.TenantId == tenantId) && (t.IsActive == false))).ToList(); } return(list); }
private static ScanSession EditScanSessionPrivate(TenantUserSession tenantUserSession, long id, string name, string description, ContextTenant context) { var scanSession = context.ScanSessions.Where(x => x.Id == id).FirstOrDefault(); if (scanSession == null) { throw (new Exception("Unable to find the following scan session")); } scanSession.Name = name; scanSession.Description = description; context.SaveChanges(); return(scanSession); }
public static ScanSession CreateScanSessionEntry(TenantUserSession tenantUserSession, string name, string description, ContextTenant context = null) { if (context == null) { using (context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { return(ScanSessionManagement.CreateScanSessionEntryPrivate(tenantUserSession, name, description, context)); } } else { return(ScanSessionManagement.CreateScanSessionEntryPrivate(tenantUserSession, name, description, context)); } }
public static ScanSession ScanSessionEntryFinalize(TenantUserSession tenantUserSession, long scanSessionId, ContextTenant context = null) { if (context == null) { using (context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { return(ScanSessionManagement.ScanSessionEntryFinalizePrivate(tenantUserSession, scanSessionId, context)); } } else { return(ScanSessionManagement.ScanSessionEntryFinalizePrivate(tenantUserSession, scanSessionId, context)); } }
//public static bool GetScanSessionById(TenantUserSession tenantUserSession, long id, out ScanSession scanSession, out Exception exception) //{ // var result = false; // scanSession = new ScanSession(); // exception = null; // try // { // if (!(ScanSessionManagement.GetScanSessionById(tenantUserSession, null, id, out scanSession, out exception))) { if (exception != null) { throw (exception); } } // } // catch (Exception ex) // { // exception = ex; // } // return result; //} public static ScanSession GetScanSessionById(TenantUserSession tenantUserSession, long id, ContextTenant context = null) { if (context == null) { using (context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { return(ScanSessionManagement.GetScanSessionByIdPrivate(tenantUserSession, id, context)); } } else { return(ScanSessionManagement.GetScanSessionByIdPrivate(tenantUserSession, id, context)); } }
private static List <ScanSession> GetAllScanSessionsPrivate(TenantUserSession tenantUserSession, ContextTenant context) { if (context == null) { throw (new ArgumentNullException("context")); } return ( context.ScanSessions .Include(x => x.Documents) .Include(x => x.Documents.Select(y => y.User)) .Include(x => x.Documents.Select(y => y.Template)) .Include(x => x.User) .ToList() ); }
public static bool GetButtonRights(TenantUserSession tenantUserSession, int UserId, int ScreenId, int buttonId) { int count = 0; using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { count = (from ur in context.UserRoles join rr in context.RoleRights on ur.RoleId equals rr.RoleId where ur.UserId == UserId && rr.Screen.Id == ScreenId && rr.Button.Id == buttonId select rr).Count(); } return(count > 0); }
public static ScanSession EditScanSession(TenantUserSession tenantUserSession, long id, string name, string description, ContextTenant context = null) { if (context == null) { using (context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { return(ScanSessionManagement.EditScanSessionPrivate(tenantUserSession, id, name, description, context)); // Audit Trail. } } else { return(ScanSessionManagement.EditScanSessionPrivate(tenantUserSession, id, name, description, context)); // Audit Trail. } }
//public static bool GetAllScanSessions(TenantUserSession tenantUserSession, out List<ScanSession> scanSessionList, out Exception exception) //{ // var result = false; // scanSessionList = new List<ScanSession>(); // exception = null; // try // { // if (!(ScanSessionManagement.GetAllScanSessions(tenantUserSession, null, out scanSessionList,out exception))) { if (exception != null) { throw (exception); } } // } // catch (Exception ex) // { // exception = ex; // } // return result; //} //internal static bool GetAllScanSessions(TenantUserSession tenantUserSession, ContextTenant context, out List<ScanSession> scanSessionList, out Exception exception) //{ // var result = false; // scanSessionList = new List<ScanSession>(); // exception = null; // try // { // if (context == null) // { // using (context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) // { // if (!(ScanSessionManagement.GetAllScanSessions(tenantUserSession, context, out scanSessionList))) { if (exception != null) { throw (exception); } } // } // } // else // { // if (!(ScanSessionManagement.GetAllScanSessions(tenantUserSession, context, out scanSessionList))) { if (exception != null) { throw (exception); } } // } // } // catch (Exception ex) // { // exception = ex; // } // return result; //} //private static bool GetAllScanSessions(TenantUserSession tenantUserSession,ContextTenant context, out List<ScanSession> scanSessionList) //{ // var result = false; // scanSessionList = context.ScanSessions // .Include(x => x.Documents) // .Include(x => x.Documents.Select(y => y.User)) // .Include(x => x.User) // .ToList(); // return result; //} public static List <ScanSession> GetAllScanSessions(TenantUserSession tenantUserSession, ContextTenant context = null) { if (context == null) { using (context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { return(ScanSessionManagement.GetAllScanSessionsPrivate(tenantUserSession, context)); // Audit Trail. } } else { return(ScanSessionManagement.GetAllScanSessionsPrivate(tenantUserSession, context)); // Audit Trail. } }
private static ScanSession GetScanSessionByIdPrivate(TenantUserSession tenantUserSession, long id, ContextTenant context) { if (context == null) { throw (new ArgumentNullException("context")); } return ( context.ScanSessions .Include(x => x.Documents) .Include(x => x.Documents.Select(y => y.User)) .Include(x => x.Documents.Select(y => y.Template)) .Include(x => x.User) .Where(x => x.Id == id) .FirstOrDefault() ); }
public static int SaveSubscription(TenantUserSession tenantUserSession, Subscription subscription) { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { if (subscription.Id < 1) { subscription = context.Subscriptions.Add(subscription); context.SaveChanges(); } else { context.Subscriptions.Attach(subscription); context.Entry(subscription).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } return(Convert.ToInt32(subscription.Id)); }
public static int SaveTenantSubscription(TenantUserSession tenantUserSession, TenantSubscription subscribtion) { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { subscribtion.Subscription = context.Subscriptions.Where(s => s.Id == subscribtion.Subscription.Id).FirstOrDefault(); subscribtion.NumberOfFormsAllowed = subscribtion.Subscription.NumberOfFormsAllowed; subscribtion.NumberOfFormsUsed = subscribtion.Subscription.NumberOfFormsUsed; subscribtion.NumberOfPagesAllowed = subscribtion.Subscription.NumberOfPagesAllowed; subscribtion.NumberOfPagesUsed = subscribtion.Subscription.NumberOfPagesUsed; subscribtion.NumberOfTemplatesAllowed = subscribtion.Subscription.NumberOfTemplatesAllowed; subscribtion.NumberOfUsersAllowed = subscribtion.Subscription.NumberOfUsersAllowed; subscribtion.NumberOfUsersUsed = subscribtion.Subscription.NumberOfUsersUsed; subscribtion = context.TenantSubscriptions.Add(subscribtion); context.SaveChanges(); } return(Convert.ToInt32(subscribtion.TenantId)); }
public static bool DeleteVendor(TenantUserSession tenantUserSession, Vendor vendor, out Exception exception) { exception = null; bool result = false; try { ContextTenant context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString); Vendor temp = context.Vendors.Where(x => x.Id == vendor.Id).Select(x => x).FirstOrDefault(); context.Vendors.Remove(temp); context.SaveChanges(); result = true; } catch (Exception ex) { exception = ex; result = false; } return(result); }
public static bool GetBlobByBatchId(TenantUserSession tenantUserSession, string BlobId, out azureblob azureblob, out Exception exception) { exception = null; azureblob = null; bool result = false; try { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { //context.Configuration.LazyLoadingEnabled = true; azureblob = context.azureblobs.Where(e => e.batchno == BlobId).FirstOrDefault <azureblob>(); result = true; } } catch (Exception ex) { exception = ex; } return(result); }
public static bool GetVendorById(TenantUserSession tenantUserSession, int VendorId, out Vendor vendor, out Exception exception) { exception = null; vendor = null; bool result = false; try { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { //context.Configuration.LazyLoadingEnabled = true; vendor = context.Vendors.Where(e => e.Id == VendorId).FirstOrDefault <Vendor>(); result = true; } } catch (Exception ex) { exception = ex; } return(result); }
public static bool GetVendorById(TenantUserSession tenantUserSession, int DocumentId, out Log auditlog, out Exception exception) { exception = null; auditlog = null; bool result = false; try { using (var context = new ContextTenant(tenantUserSession.Tenant.DatabaseConnectionString)) { //context.Configuration.LazyLoadingEnabled = true; auditlog = context.Logs.Where(e => e.Id == DocumentId).FirstOrDefault <Log>(); result = true; } } catch (Exception ex) { exception = ex; } return(result); }