Exemplo n.º 1
0
        internal ContactInformation ToModel()
        {
            State        state = null;
            List <State> list  = StaticCache.GetStates();

            if (this.StateId != 0)
            {
                state = new State();
                state = list.Single(s => s.Id == this.StateId);
            }
            else if (this.State != null)
            {
                state = new State();
                state = list.Single(s => s.Name == this.State);
            }
            var contactInfo = new ContactInformation
            {
                Id       = this.Id,
                Address1 = this.Address1,
                Address2 = this.Address2,
                City     = this.City,
                State    = state,
                StateId  = state.Id,
                ZipCode  = this.Zip,
                Country  = null,
                Email1   = this.Email1,
                Phone1   = this.Phone1,
                Website1 = this.Website1
            };


            return(contactInfo);
        }
Exemplo n.º 2
0
        private OrganizationVm SaveModel(OrganizationVm organization, HttpResponseMessage response)
        {
            OrganizationVm   newOrganization        = null;
            WorkflowInstance workflowInstanceToSave = null;

            try
            {
                bool populateInitialLocation = false;
                var  workflowInstance        = organization.WorkflowInstance;

                if (organization.Id == 0)
                {
                    populateInitialLocation = true;
                }
                var start = DateTime.Now;
                Debug.WriteLine("####Entering Get States: " + start);
                var state = StaticCache.GetStates().First(s => s.Id == organization.ContactInformation.StateId);
                var end   = DateTime.Now;
                Debug.WriteLine("#####Total Get State time: " + end.Subtract(start));
                start = DateTime.Now;
                Debug.WriteLine("####Entering Save Org: " + start);
                organization.ContactInformation.StateId = state.Id;
                var organizationToSave = organization.ToModel();
                organizationService.Save(organizationToSave);
                newOrganization = OrganizationVm.FromModel(organizationToSave);
                end             = DateTime.Now;
                Debug.WriteLine("#####Total Save org time: " + end.Subtract(start));
                newOrganization.Saved = true;
                if (populateInitialLocation)
                {
                    newOrganization.Locations = SaveLocationOnFirstSave(newOrganization);
                }
                if (workflowInstance != null)
                {
                    workflowInstanceToSave = workflowInstance.ToModel();
                    workflowInstanceToSave.OrganizationId = organizationToSave.Id;
                }
            }
            catch (Exception e)
            {
                emailHelper.SendErrorEmail(e);
                newOrganization.Saved = false;
            }
            //as long as organization saves, don't worry about workflow state, just send an email
            try
            {
                this.workflowInstanceService.Save(workflowInstanceToSave);
                if (workflowInstanceToSave != null)
                {
                    newOrganization.WorkflowInstance = WorkflowInstanceVm.FromModel(workflowInstanceToSave);
                }
            }
            catch
            {
                //Not emailing this because it's not a real error in this location. It's an expected exception when thhe org is saved outside the workflow
                //emailHelper.SendErrorEmail(e);
            }
            return(newOrganization);
        }
Exemplo n.º 3
0
 // GET api/geography
 public IEnumerable <State> Get()
 {
     return(StaticCache.GetStates().AsEnumerable());
 }