コード例 #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
ファイル: TenantManagement.cs プロジェクト: radtek/Cobox
        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));
        }
コード例 #3
0
ファイル: TenantManagement.cs プロジェクト: radtek/Cobox
 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));
 }
コード例 #4
0
        public static bool TenantDocumentPerformOcr(Tenant tenant, Document document, WorkerRoleParameters workerRoleParameters, out Exception exception)
        {
            var      result      = false;
            Document ocrDocument = null;
            List <DocumentTemplate> ocrDocumentTemplate = null;
            List <DocumentFragment> ocrDocumentFragment = null;

            exception = null;

            try
            {
                List <Template>        allTemplates = null;
                List <TemplateElement> allElements  = null;

                using (var context = new ContextTenant(tenant.DatabaseConnectionString))
                {
                    allTemplates = context
                                   .Templates
                                   .AsNoTracking()
                                   .Include(t => t.Elements)
                                   .Include(t => t.Elements.Select(x => x.ElementDetails))
                                   .Where(t => (t.IsActive == true) && (t.IsFinalized == true))
                                   .ToList();

                    if (allTemplates.Count <= 0)
                    {
                        throw (new Exception("No templates found."));
                    }
                }

                // workerRoleParameters???

                // Download file from azure.
                Stream stream = null;
                List <OcrResultInfo> ocrresultinfos = new List <OcrResultInfo> ();

                if (WorkerRoleSimulation.GetTenantDocumentFileStream(tenant, document, out stream, out exception))
                {
                    Image documentImage = null;

                    using (var image = Image.FromStream(stream))
                    {
                        documentImage = (Image)image.Clone();
                        // LeadTools code.
                        // Stream and image available.
                    }

                    // TODO: Replace with Server.MapPath.
                    //LeadToolsOCR leadtoolsocr = new LeadToolsOCR (workerRoleParameters.OcrEngineSettings.GetPathData().FullName, tenant.Id.ToString (), string.Empty, out exception);
                    //if (exception != null) { throw exception; }

                    List <LeadtoolsBarcodeData> barcodedata = null;
                    bool foundbarcode = false;                     // leadtoolsocr.ReadBarcode (documentImage, out barcodedata, out exception);
                    //if (exception != null) { throw exception; }

                    if (foundbarcode)
                    {
                        //What to do if multiple barcodes are found.
                        int  templateid = 0;
                        bool foundId    = int.TryParse(barcodedata.First().Value, out templateid);
                        if (!(foundId) || templateid <= 0)
                        {
                        }                          //What to do if Form Id is Not Found by the barcode
                        Template template = allTemplates.Where(t => t.Id == ((long)templateid)).ToArray().FirstOrDefault();
                        if (template.TemplateType == TemplateType.Form)
                        {
                            double _computeddifference = 0.0;
                            if ((documentImage.Width <= documentImage.Height) && (!(documentImage.Height <= 0)))
                            {
                                _computeddifference = ((Convert.ToDouble(documentImage.Width)) / (Convert.ToDouble(documentImage.Height)));
                            }
                            else
                            {
                                if (!(documentImage.Width <= 0))
                                {
                                    _computeddifference = documentImage.Height / documentImage.Width;
                                }
                            }
                            var elements = allElements.Where(e => e.TemplateId == (long)templateid).ToList();
                            List <ComputeCoordinates> cordlistlist = new List <ComputeCoordinates> ();
                            //cordlistlist = leadtoolsocr.GetAllZoneData (elements, _computeddifference, documentImage);

                            //what to do with form matched results


                            //foreach (ComputeCoordinates cordata in cordlistlist)
                            //{
                            //    returnedresult += cordata.Text;
                            //}
                        }
                    }
                    else
                    {
                        result = AutoOCR(workerRoleParameters.OcrEngineSettings, tenant, documentImage, document, allTemplates, out ocrDocument, out ocrDocumentFragment, out ocrDocumentTemplate, out exception);
                        if (exception != null)
                        {
                            throw exception;
                        }
                    }

                    // Perform OCR and time-consuming tasks.
                }
                else
                {
                    throw (exception);
                }

                using (var context = new ContextTenant(tenant.DatabaseConnectionString))
                {
                    using (var transaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            if (ocrDocument != null)
                            {
                                context.Documents.Attach(ocrDocument);
                                context.Entry(ocrDocument).State = EntityState.Modified;
                                context.SaveChanges();
                            }
                            if (ocrDocumentFragment != null)
                            {
                                foreach (var documentfragment in ocrDocumentFragment)
                                {
                                    context.DocumentFragments.Add(documentfragment);
                                    context.SaveChanges();
                                }
                            }
                            if (ocrDocumentTemplate != null)
                            {
                                foreach (var documenttemplate in ocrDocumentTemplate)
                                {
                                    context.DocumentTemplate.Add(documenttemplate);
                                    context.SaveChanges();
                                }
                            }
                            //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);
        }