public HttpResponseMessage GetOrgs() { var orgs = _OrgService.GetOrgs().Where(p => p.InactiveDate == null); var result = PlatformMappingHelper.Map <IList <Org>, IList <OrgDTO> >(orgs.ToList()).ToList(); if (result == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <IEnumerable <OrgDTO> >(HttpStatusCode.OK, result)); }
public HttpResponseMessage OrgList() { List <dynamic> orgs = new List <dynamic>(); int org_id = int.Parse(Request.Headers.GetValues("orgId").FirstOrDefault()); if (org_id == 1) { orgs.AddRange(_IOrgService.GetOrgs().Where(o => o.Id != 1).Select(p => new { Id = p.Id, Name = p.Name }).ToList()); } else { var reseller = _IOrgService.GetOrg(org_id); orgs.Add(new { Id = reseller.Id, Name = reseller.Name }); orgs.AddRange(_IOrgorgService.GetOrgorgs().Where(o => o.OrgId == org_id).Select(p => new { Id = p.Org1.Id, Name = p.Org1.Name })); } return(Request.CreateResponse(HttpStatusCode.OK, orgs)); }
public HttpResponseMessage GetCustomers() { DateTime start = DateTime.Now; try { int?org_id = int.Parse(Request.Headers.GetValues("orgId").FirstOrDefault()); var org = _IOrgService.GetOrgs().Where(p => p.Id == org_id).FirstOrDefault(); if (org != null) { IList <Object> result = new List <object>(); if (org.OrgTyp.TypCd == "CUST") { result.Add(new { soKey = org.soKey, Name = org.Name }); } else { foreach (OrgOrg custorg in org.OrgOrgs1) { result.Add(new { soKey = custorg.Org1.soKey, Name = custorg.Org1.Name }); } } ApiLog.Write("GetCustomers", start); return(Request.CreateResponse(HttpStatusCode.OK, result)); } else { var createresponse = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid Org Key"); throw new HttpResponseException(createresponse); } } catch (Exception e) { var createresponse = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Error Retriving Version Number/StorageAccessKey"); throw new HttpResponseException(createresponse); } }
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 ReSellers() { var otoss = _IOrgService.GetOrgs().Where(p => p.OrgTyp.TypCd != "CUST").Select(o => new { id = o.Id, Name = o.Name }); return(Request.CreateResponse <IEnumerable <Object> >(HttpStatusCode.OK, otoss)); }
public string GetOrgs() { return(JsonHelper.Instance.Serialize(_orgService.GetOrgs(CurrentUser.OrgFullPath))); }