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 Statuses() { var otoss = _IOrgtyporgstatusService.GetOrgtyporgstatus().FindAll(p => p.OrgTyp.Name == "Customer").Select(o => new { Id = o.Id, StatusCd = o.OrgStatus.StatusCd, Name = o.OrgStatus.DisplayText }); return(Request.CreateResponse <IEnumerable <Object> >(HttpStatusCode.OK, otoss)); }