// GET api/organization public HttpResponseMessage GetById(int id) { try { var organization = organizationService.Get(id); var userId = webSecurityService.CurrentUserId; bool isAdmin = organizationService.IsAdminOfOrganization(userId, organization.Id); if (!isAdmin) { organization.Budget = 0; organization.Admin = null; organization.Subscription = null; } var vm = OrganizationVm.FromModel(organization); var instance = this.workflowInstanceService.Get(wi => wi.OrganizationId == id).FirstOrDefault(); if (instance != null) { vm.WorkflowInstance = WorkflowInstanceVm.FromModel(instance); } return(Request.CreateResponse(HttpStatusCode.OK, vm)); } catch (Exception e) { emailHelper.SendErrorEmail(e); } return(Request.CreateResponse(HttpStatusCode.InternalServerError)); }
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); }
public HttpResponseMessage Put(WorkflowInstanceVm workflowInstance) { var model = workflowInstance.ToModel(); try { this.workflowInstanceService.Save(model); } catch (Exception e) { emailHelper.SendErrorEmail(e); } var response = Request.CreateResponse(HttpStatusCode.OK, WorkflowInstanceVm.FromModel(model)); return(response); }
public virtual ActionResult SignUp(int?id) { try { OrganizationVm model = null; if (id == null) { if (this.userService.CurrentUserId != -1) { var orgs = this.organizationService.GetByAdministrator().ToList(); //they've laready signedup before if (orgs.Count() > 1) { //select first incomplete org registration foreach (var org in orgs) { //Check workflow if it is complete, if no get Org ID model = OrganizationVm.FromModel(this.organizationService.Get(org.Id)); var instance = this.workflowInstanceService.Get(wi => wi.OrganizationId == model.Id).FirstOrDefault(); if (instance != null) { model.WorkflowInstance = WorkflowInstanceVm.FromModel(instance); //This org isn't complete, so let it finish if (model.WorkflowInstance != null && !model.WorkflowInstance.IsComplete) { break; } else { } } } //var incompleteOrgId = orgs.Select( } else if (orgs.Count() == 1) { //Check workflow if it is complete, if no get Org ID model = OrganizationVm.FromModel(this.organizationService.Get(orgs.ElementAt(0).Id)); var instance = this.workflowInstanceService.Get(wi => wi.OrganizationId == model.Id).FirstOrDefault(); if (instance != null) { model.WorkflowInstance = WorkflowInstanceVm.FromModel(instance); if (model.WorkflowInstance != null && model.WorkflowInstance.IsComplete) { model = new OrganizationVm(); model.Id = 0; } //This org isn't complete, so let it finish } } else { model = new OrganizationVm(); model.Id = 0; } } else { model = new OrganizationVm(); model.Id = 0; } } else { int orgId = 0; Int32.TryParse(id.ToString(), out orgId);; model = OrganizationVm.FromModel(this.organizationService.Get(orgId)); } return(View(model)); } catch (Exception e) { this.emailHelper.SendErrorEmail(e); } return(View(WENEEDUHAVE.Error.Views.Index)); }