public HttpResponseMessage Signup(SignupRequestInfo signupRequestInfo) { OrgCust newCustomer = new OrgCust(); OrgReseller newReseller = new OrgReseller(); try { var rolename = 0; bool isNewCustomer = signupRequestInfo.userType == "RESE" ? false : true; var orgCustomerType = _IOrgtypService.GetOrgtyps().Where(p => p.TypCd == SystemConstants.ORG_TYPE_CD_CUSTOMER).FirstOrDefault(); var orgResellerType = _IOrgtypService.GetOrgtyps().Where(p => p.TypCd == SystemConstants.ORG_TYPE_CD_RESELLER).FirstOrDefault(); var newOrg = _IOrgService.GetOrgs().Where(p => p.soKey == Guid.Parse(signupRequestInfo.id)).FirstOrDefault(); if (newOrg == null) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid Invitation")); } Locn newLocn = new Locn { AddressLine1 = signupRequestInfo.addressStreet1, AddressLine2 = signupRequestInfo.addressStreet2, City = signupRequestInfo.addressCity, DateLastMaint = DateTime.UtcNow, CreateDate = DateTime.UtcNow, State = signupRequestInfo.addressState, ZipCode = signupRequestInfo.addressZip }; var os = _IOrgtyporgstatusService.GetOrgtyporgstatus().Where(p => p.OrgStatus.StatusCd == "INREVIEW").FirstOrDefault(); newOrg.OrgStatusHists.Add(new OrgStatusHist() { Org = newOrg, OrgTypOrgStatu = os, CreateDate = DateTime.UtcNow }); // Associate Organization to Location newOrg.OrgLocns.Add(new OrgLocn { Locn = newLocn, Org = newOrg }); // Created New OrgCust or OrgReseller based on request if (isNewCustomer) { rolename = 2; } else { rolename = 3; } _IOrgService.UpdateOrg(newOrg); // Create User var newuser = _IUserService.GetUsers().Where(p => p.UserName == signupRequestInfo.email).FirstOrDefault(); var ctype = _IContacttypService.GetContacttyps().Find(p => p.ContactTypCd == "PHON"); var contact = new Contact { ContactTyp = ctype, Value = signupRequestInfo.phone }; var curDateTime = DateTime.UtcNow; var guid = Guid.NewGuid(); if (newuser.Per == null) { Per per = new Per() { FirstName = signupRequestInfo.firstName, LastName = signupRequestInfo.lastName, MiddleName = signupRequestInfo.middleName, Createdate = curDateTime, Title = signupRequestInfo.contactTitle }; newuser.Per = per; } else { newuser.Per.FirstName = signupRequestInfo.firstName; newuser.Per.MiddleName = signupRequestInfo.middleName; newuser.Per.LastName = signupRequestInfo.lastName; newuser.Per.Title = signupRequestInfo.contactTitle; } newuser.Per.PersContacts.Add(new PersContact() { Per = newuser.Per, Contact = contact }); var authrole = _IAuthrolService.GetAuthrol(rolename); newuser.UserAuthRols.Add(new UserAuthRol() { User = newuser, AuthRol = authrole }); newuser.InactiveDate = null; newuser.InviteDate = null; var messagetemp = _IMessagetemplateService.GetMessagetemplates().Where(p => p.Name == "SignupAccepted").FirstOrDefault(); var baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority); if (messagetemp != null) { newuser.MessageUsers.Add(new MessageUser() { User = newuser, DeliveryMethodId = 1, Message = new Message() { CreateDate = curDateTime, HeaderText = messagetemp.HeaderText, MessageBody = messagetemp.TemplateText + "\n" + baseUrl + "/login" } }); } _IUserService.UpdateUser(newuser); _IUserService.UpdatePassword(signupRequestInfo.email, PasswordHash.CreateHash(signupRequestInfo.password)); // Create Sign Up Workflow WkflowDef signUpWorkflow; int wkflowDefId = isNewCustomer ? 1 : 2; // 1= customer signup , 2 = reseller signup signUpWorkflow = _IWkflowdefService.GetWkflowdefs().Where(p => p.Id == wkflowDefId).FirstOrDefault(); var signUpWorkflowInstance = new WkflowInstance { CreateDate = DateTime.UtcNow, DateLastMaint = DateTime.UtcNow, WkflowDefId = signUpWorkflow.Id, OrgId = newOrg.Id, UserId = 1, CurrWkflowStatId = 5//InReview State }; signUpWorkflowInstance.WkflowStepHists.Add(new WkflowStepHist { CreateDate = DateTime.UtcNow, DateLastMaint = DateTime.UtcNow, WkflowStatId = 5, CreatedUserId = 1 }); _IWkflowinstanceService.AddWkflowinstance(signUpWorkflowInstance); return(Request.CreateResponse <bool>(HttpStatusCode.OK, true)); } catch (Exception daExp) { return(Request.CreateResponse <bool>(HttpStatusCode.InternalServerError, false)); } }
public HttpResponseMessage Invite(UserDTO userDTO) { try { var user = _IUserService.GetUsers().Where(p => p.UserName == userDTO.userName); if (user.Count() <= 0) { int userID = int.Parse(Request.Headers.GetValues("userId").FirstOrDefault()); var curDateTime = DateTime.UtcNow; var guid = Guid.NewGuid(); var newuser = new User() { UserName = userDTO.userName, Password = "", Per = new Per() { FirstName = userDTO.firstName, LastName = userDTO.lastName, MiddleName = userDTO.middleName, Createdate = curDateTime }, CreateDate = curDateTime, IsProcess = false, soKey = guid, CreateUserId = userID, InviteDate = curDateTime, IsSuperAdmin = false }; var org = _IOrgService.GetOrg(userDTO.orgId); AuthRol authrole; if (org.OrgTyp.TypCd == "TENA") { authrole = _IAuthrolService.GetAuthrol(2); } else if (org.OrgTyp.TypCd == "RESE") { authrole = _IAuthrolService.GetAuthrol(4); } else { authrole = _IAuthrolService.GetAuthrol(3); } newuser.UserAuthRols.Add(new UserAuthRol() { User = newuser, AuthRol = authrole }); newuser.PortUsers.Add(new PortUser() { User = newuser, PortId = 1 }); newuser.OrgUsers.Add(new OrgUser() { User = newuser, Org = org }); var messagetemp = _IMessagetemplateService.GetMessagetemplates().Where(p => p.Name == "InviteUser").FirstOrDefault(); var baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority); var url = baseUrl + "/user/" + guid.ToString() + "/signup"; if (messagetemp != null) { newuser.MessageUsers.Add(new MessageUser() { User = newuser, DeliveryMethodId = 1, Message = new Message() { CreateDate = curDateTime, HeaderText = messagetemp.HeaderText, MessageBody = string.Format(messagetemp.TemplateText, url) } }); } _IUserService.AddUser(newuser); } else { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "UserName Needs to be Unique")); } } catch (Exception e) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <bool>(HttpStatusCode.OK, true)); }