public HttpResponseMessage Create(DocTypDTO docTypeDTO) { try { int userID = int.Parse(Request.Headers.GetValues("userId").FirstOrDefault()); int statusID = _IDoctypstatusService.GetDoctypstatus().Where(p => p.StatusCd == "INREVIEW").FirstOrDefault().Id; var sameNames = _IOrgdoctypService.GetOrgdoctyps().Where(p => p.OrgId == docTypeDTO.OrgId && p.Descript == docTypeDTO.Descript); if (sameNames.Count() <= 0) { var DocTypWorkflowdef = _IWkflowdefService.GetWkflowdefs().Where(p => p.Code == "DTSW").FirstOrDefault(); var wkstatusID = DocTypWorkflowdef.WkflowDefWkflowStats.Where(p => p.WkflowStat.Code == "INREVIEW").FirstOrDefault().WkflowStatId; var messagetemp = _IMessagetemplateService.GetMessagetemplates().Where(p => p.Name == "NewDocTypeSetup").FirstOrDefault(); var user = _IUserService.GetUser(userID); // Create a new Document Type Setup workflow var batchWkflowInstance = new WkflowInstance { CreateDate = DateTime.UtcNow, WkflowDefId = DocTypWorkflowdef.Id, OrgId = docTypeDTO.OrgId, User = user, CurrWkflowStatId = wkstatusID }; // Set INIT state for new workflow instance. batchWkflowInstance.WkflowStepHists.Add(new WkflowStepHist { CreateDate = DateTime.UtcNow, WkflowStatId = wkstatusID, CreatedUserId = userID }); if (messagetemp != null) { _IMessageuserService.AddMessageuser(new MessageUser() { User = user, DeliveryMethodId = 1, Message = new Message() { CreateDate = DateTime.UtcNow, WkflowInstance = batchWkflowInstance, HeaderText = messagetemp.HeaderText, MessageBody = string.Format(messagetemp.TemplateText, docTypeDTO.Name) } }); } _IWkflowinstanceService.AddWkflowinstance(batchWkflowInstance); _IOrgdoctypService.CreateNewDocType(docTypeDTO, userID, statusID); _UnitOfWork.Commit(); } else { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "DocType Name Should be Unique")); } } catch (Exception e) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <bool>(HttpStatusCode.OK, true)); }
public HttpResponseMessage Invite(InviteRequestInfo customer) { try { if (customer.ParentId == null) { customer.ParentId = 1; } int?org_id = int.Parse(Request.Headers.GetValues("orgId").FirstOrDefault()); var user = _IUserService.GetUsers().Where(p => p.UserName == customer.Email); if (user.Count() > 0) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Customer Email already exists in our system")); } int userID = int.Parse(Request.Headers.GetValues("userId").FirstOrDefault()); var excustomer = _IOrgService.GetOrgs().Where(p => p.Name == customer.Name); var curDateTime = DateTime.UtcNow; if (excustomer.Count() <= 0) { OrgTyp custType; if (customer.TypeId == 6) { custType = _IOrgtypService.GetOrgtyps().Where(p => p.TypCd == "CUST").FirstOrDefault(); } else { custType = _IOrgtypService.GetOrgtyps().Where(p => p.TypCd == "RESE").FirstOrDefault(); } var cguid = Guid.NewGuid(); Org newOrg = new Org { Name = customer.Name, CreateDate = DateTime.UtcNow, CreatedUserId = userID, ModifiedDate = DateTime.UtcNow, ModifiedUserId = userID, InviteDate = DateTime.UtcNow, OrgTypId = custType.Id, soKey = cguid, }; var parentOrg = _IOrgService.GetOrg(customer.ParentId); if (customer.TypeId == 6) { OrgCust newCustomer = new OrgCust() { Org = newOrg, }; _IOrgcustService.AddOrgcust(newCustomer); } else { OrgReseller newReseller = new OrgReseller() { Org = newOrg, }; _IOrgresellerService.AddOrgreseller(newReseller); } _IOrgorgService.AddOrgorg(new OrgOrg() { Org = parentOrg, AssociatedOrgId = newOrg.Id }); var orgTypeStatus = _IOrgtyporgstatusService.GetOrgtyporgstatus().Where(p => p.OrgTyp.TypCd == "CUST" && p.OrgStatus.StatusCd == "INVITED").FirstOrDefault(); newOrg.OrgStatusHists.Add(new OrgStatusHist() { Org = newOrg, OrgTypOrgStatu = orgTypeStatus, CreateDate = DateTime.UtcNow }); var guid = Guid.NewGuid(); var newuser = new User() { UserName = customer.Email, Password = "", Per = new Per() { FirstName = "", LastName = "", MiddleName = "", Createdate = curDateTime }, CreateDate = curDateTime, IsProcess = false, soKey = guid, CreateUserId = userID, InviteDate = curDateTime, IsSuperAdmin = false }; var authrole = _IAuthrolService.GetAuthrols().Where(p => p.Name == "Customer Admin").FirstOrDefault(); 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 = newOrg, Type = "Primary" }); var Singupmessagetemp = _IMessagetemplateService.GetMessagetemplates().Where(p => p.Name == "Signup").FirstOrDefault(); var messagetemp = _IMessagetemplateService.GetMessagetemplates().Where(p => p.Name == "InviteUser").FirstOrDefault(); var baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority); string Singupurl; if (customer.TypeId == 6) { Singupurl = baseUrl + "/cust/" + cguid.ToString() + "/signup"; } else { Singupurl = baseUrl + "/resel/" + cguid.ToString() + "/signup"; } if (Singupmessagetemp != null) { newuser.MessageUsers.Add(new MessageUser() { User = newuser, DeliveryMethodId = 1, Message = new Message() { CreateDate = curDateTime, HeaderText = Singupmessagetemp.HeaderText, MessageBody = string.Format(Singupmessagetemp.TemplateText, Singupurl) } }); } _IUserService.AddUser(newuser); } else { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Customer Name already exists in our system")); } } catch (Exception e) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <bool>(HttpStatusCode.OK, true)); }
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)); }