Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        private static void InitializeLocalDatabases()
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.Write($"InitializeLocalDatabases.");

            ContextMaster.Initialize();
            ContextDesktop.Initialize(AffinityConfigurationDesktop.GetDatabaseConnectionStringBuilder(AffinityConfiguration.DeploymentLocation).ConnectionString);

            using (var contextDesktop = new ContextDesktop(AffinityConfigurationDesktop.GetDatabaseConnectionStringBuilder(AffinityConfiguration.DeploymentLocation).ConnectionString))
            {
            }

            using (var contextMaster = new ContextMaster())
            {
                var tenants = contextMaster.Tenants.ToList();

                foreach (var tenant in tenants)
                {
                    ContextTenant.Initialize(tenant.DatabaseConnectionString, true);

                    using (var contextTenant = new ContextTenant(tenant.DatabaseConnectionString))
                    {
                        contextTenant.Cultures.ToString();
                    }
                }
            }
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        private static void FarazTestFunction1()
        {
            var toContinue = false;

            do
            {
                toContinue = false;
                Console.WriteLine(AffinityConfigurationMaster.GetDatabaseConnectionStringBuilder(DeploymentLocation.BtsFaraz).ToString());
                Exception         exception = null;
                TenantUserSession tenantUserSessionRaheel = null;
                TenantUserSession tenantUserSessionJunaid = null;
                AuthenticationManagement.SignIn(SessionType.Mvc, "kloud-soft.com", "raheel.khan", Sha.GenerateHash("audience", GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind), IPAddress.Loopback.ToString(), "User Agent", 0, "Session Id", out tenantUserSessionRaheel, out exception);
                AuthenticationManagement.SignIn(SessionType.Mvc, "kloud-soft.com", "junaid.sayed", Sha.GenerateHash("audience", GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind), IPAddress.Loopback.ToString(), "User Agent", 0, "Session Id", out tenantUserSessionJunaid, out exception);
                List <Folder> folders = null;
                using (var context = new ContextTenant(tenantUserSessionRaheel.Tenant.DatabaseConnectionString))
                {
                    folders = context.Folders.Include(x => x.FolderUsers).ToList();
                    Console.WriteLine(FolderManagement.ValidateUserFolderRightsHirarchy(15, folders, 1).ToString());
                }
                Console.WriteLine("press 'y' to continue");
                var read = Console.ReadKey();
                if (read.KeyChar.ToString().ToLower() == "y")
                {
                    toContinue = true;
                    Console.Clear();
                }
            } while (toContinue);
        }
Пример #9
0
        public static bool ValidateInviteKeyAndCredentials
        (
            SessionType sessionType,
            Guid inviteGuid,
            string domain,
            string email,
            string currentPassword,
            double InviteTimeOutHrs,
            out Tenant tenantDatabase,
            out Exception exception
        )
        {
            var  result = false;
            User user   = null;
            var  now    = DateTime.UtcNow;

            tenantDatabase = null;
            exception      = null;
            try
            {
                if (!MasterTenantManagement.GetTenantByDomain(domain, out tenantDatabase, out exception))
                {
                    throw (exception);
                }
                if (tenantDatabase == null)
                {
                    throw (new DomainNotFoundException());
                }
                using (var context = new ContextTenant(tenantDatabase.DatabaseConnectionString))
                {
                    user = context.Users.Where(x => x.InviteGuid == inviteGuid && x.Email == email).SingleOrDefault();
                    if (user == null)
                    {
                        throw new Exception(@"Unable to find the invitation. This might happen for the follwoing reason:" + Environment.NewLine + "1) If the user is already a member." + Environment.NewLine + "2)Invalid key or domain." + Environment.NewLine + "3)Invalid credentials.");
                    }
                    var expiryDate = user.DateTimeCreated.AddHours(InviteTimeOutHrs);
                    if (DateTime.UtcNow >= expiryDate)
                    {
                        throw new Exception("The invitation was expired, please contact the sender for a new invitation.");
                    }
                    string passwordHash = "";
                    if (!Sha.GenerateHash((currentPassword ?? ""), GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind, out passwordHash, out exception))
                    {
                        throw (exception);
                    }
                    if (!PasswordHash.ValidatePassword(passwordHash, user.PasswordHash))
                    {
                        throw (new AuthenticationException(isValidDomain: true, isValidUsername: true, isValidPassword: false));
                    }
                    result = true;
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            return(result);
        }
Пример #10
0
 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));
 }
Пример #11
0
        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));
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }
Пример #16
0
        public static bool TenantDocumentUpdate(Tenant tenant, Document document, out Exception exception)
        {
            var result = false;

            exception = null;

            try
            {
                var templates         = new List <Template>();
                var documentFragments = new List <DocumentFragment>();

                using (var context = new ContextTenant(tenant.DatabaseConnectionString))
                {
                    templates = context
                                .Templates
                                .AsNoTracking()
                                .Include(t => t.Elements)
                                .ToList();

                    // document
                    // Zones from OCR: Keep in a memory data structure.
                    // Zones to element matching will happen in memory only.
                }

                // Perform OCR and time-consuming tasks.

                using (var context = new ContextTenant(tenant.DatabaseConnectionString))
                {
                    using (var transaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            //context.Templates.Attach(templates[0]);
                            context.SaveChanges();

                            // Do not call this line from anywhere else.
                            transaction.Commit();
                        }
                        catch (Exception e)
                        {
                            transaction.Rollback();
                        }
                    }
                }

                result = true;
            }
            catch (Exception e)
            {
                exception = e;
            }

            return(result);
        }
Пример #17
0
        public static bool SignOut(string domain, string username, string token, out Exception exception)
        {
            var    result = false;
            Tenant tenant = null;

            exception = null;

            try
            {
                if (!MasterTenantManagement.GetTenantByDomain(domain, out tenant, out exception))
                {
                    throw (exception);
                }
                if (tenant == null)
                {
                    throw (new DomainNotFoundException());
                }

                using (var context = new ContextTenant(tenant.DatabaseConnectionString))
                {
                    var user    = context.Users.SingleOrDefault(s => s.UserName == username);
                    var session = context.Sessions.SingleOrDefault(s => s.Token == token);

                    if (user == null)
                    {
                        throw (new TokenInvalidException());
                    }
                    if (session == null)
                    {
                        throw (new TokenInvalidException());
                    }
                    if (session.UserId != user.Id)
                    {
                        throw (new TokenInvalidException());
                    }
                    if (session.TenantId != tenant.Id)
                    {
                        throw (new TokenInvalidException());
                    }

                    session.DateTimeExpiration = DateTime.UtcNow.Subtract(TimeSpan.FromSeconds(1));

                    context.SaveChanges();

                    result = true;
                }
            }
            catch (Exception e)
            {
                exception = e;
            }

            return(result);
        }
Пример #18
0
        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);
        }
Пример #19
0
 //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));
     }
 }
Пример #20
0
 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));
     }
 }
Пример #21
0
 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));
     }
 }
Пример #22
0
        public static bool ValidateInviteKey
        (
            SessionType sessionType,
            Guid inviteGuid,
            string domain,
            double InviteTimeOutHrs,
            out Tenant tenantDatabase,
            out Exception exception
        )
        {
            var  result       = false;
            User userDatabase = null;
            var  now          = DateTime.UtcNow;

            tenantDatabase = null;
            exception      = null;
            try
            {
                if (!MasterTenantManagement.GetTenantByDomain(domain, out tenantDatabase, out exception))
                {
                    throw (exception);
                }
                if (tenantDatabase == null)
                {
                    throw (new DomainNotFoundException());
                }
                using (var context = new ContextTenant(tenantDatabase.DatabaseConnectionString))
                {
                    tenantDatabase = context.Tenants.SingleOrDefault();
                    userDatabase   = context.Users.Where(x => x.InviteGuid == inviteGuid).SingleOrDefault();
                    if (userDatabase == null)
                    {
                        throw new Exception("Unable to find the invitation. This might happen for the follwoing reason:" + Environment.NewLine + "1) If the user is already a member." + Environment.NewLine + "2)Invalid key or domain");
                    }
                    var expiryDate = userDatabase.DateTimeCreated.AddHours(InviteTimeOutHrs);
                    if (DateTime.UtcNow >= expiryDate)
                    {
                        throw new Exception("The invitation was expired, please contact the sender for a new invitation.");
                    }
                    result = true;
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            return(result);
        }
Пример #23
0
        //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.
            }
        }
Пример #24
0
        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);
        }
Пример #25
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.
     }
 }
Пример #26
0
        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));
        }
Пример #27
0
 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));
 }
Пример #28
0
        public static bool TenantDocumentGet(Tenant tenant, out Document document, out Exception exception)
        {
            var result = false;

            document  = null;
            exception = null;

            try
            {
                using (var context = new ContextTenant(tenant.DatabaseConnectionString))
                {
                    var documentTemp = context
                                       .Documents
                                       .Where(d => (((d.State == DocumentState.QueuedAuto) || (d.State == DocumentState.QueuedManual)) && (d.CountAttemptOcr <= 3) && (d.LatestCheckedOutByUserId <= 0)))
                                       .FirstOrDefault();

                    if (documentTemp != null)
                    {
                        documentTemp.CountAttemptOcr++;
                        if (documentTemp.Confidence == null)
                        {
                            documentTemp.Confidence = 0;
                        }
                        context.SaveChanges();

                        document = context
                                   .Documents
                                   .AsNoTracking()
                                   .Include(d => d.User)
                                   .Include(d => d.Folder)
                                   .Single(d => d.Id == documentTemp.Id);
                    }
                }

                result = true;
            }
            catch (Exception e)
            {
                exception = e;
                document  = null;
            }

            return(result);
        }
Пример #29
0
        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);
        }
Пример #30
0
        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);
        }