public string GetBranchesByUserId(string token) { token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int userId = 0; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemId") { userId = int.Parse(c.Value); } } using (incposdbEntities entity = new incposdbEntities()) { var List = (from S in entity.branchesUsers join B in entity.branches on S.branchId equals B.branchId into JB join U in entity.users on S.userId equals U.userId into JU from JBB in JB.DefaultIfEmpty() from JUU in JU.DefaultIfEmpty() where S.userId == userId select new BranchesUsersModel() { branchsUsersId = S.branchsUsersId, branchId = S.branchId, userId = S.userId, createDate = S.createDate, updateDate = S.updateDate, createUserId = S.createUserId, updateUserId = S.updateUserId, // branch bbranchId = JBB.branchId, bcode = JBB.code, bname = JBB.name, baddress = JBB.address, bemail = JBB.email, bphone = JBB.phone, bmobile = JBB.mobile, bcreateDate = JBB.createDate, bupdateDate = JBB.updateDate, bcreateUserId = JBB.createUserId, bupdateUserId = JBB.updateUserId, bnotes = JBB.notes, bparentId = JBB.parentId, bisActive = JBB.isActive, btype = JBB.type, // user uuserId = JUU.userId, uusername = JUU.username, upassword = JUU.password, uname = JUU.name, ulastname = JUU.lastname, ujob = JUU.job, uworkHours = JUU.workHours, ucreateDate = JUU.createDate, uupdateDate = JUU.updateDate, ucreateUserId = JUU.createUserId, uupdateUserId = JUU.updateUserId, uphone = JUU.phone, umobile = JUU.mobile, uemail = JUU.email, unotes = JUU.notes, uaddress = JUU.address, uisActive = JUU.isActive, uisOnline = JUU.isOnline, uimage = JUU.image, }).ToList(); return(TokenManager.GenerateToken(List)); } } }
public IHttpActionResult Get() { var re = Request; var headers = re.Headers; string token = ""; if (headers.Contains("APIKey")) { token = headers.GetValues("APIKey").First(); } Validation validation = new Validation(); bool valid = validation.CheckApiKey(token); if (valid) // APIKey is valid { using (incposdbEntities entity = new incposdbEntities()) { var medalsList = (from MA in entity.medalAgent join M in entity.medals on MA.medalId equals M.medalId into JM join A in entity.agents on MA.agentId equals A.agentId into JA join U in entity.users on MA.createUserId equals U.userId into JU from JMM in JM.DefaultIfEmpty() from JAA in JA.DefaultIfEmpty() from JUU in JU.DefaultIfEmpty() select new MedalAgentModel() { id = MA.id, medalId = MA.medalId, agentId = MA.agentId, notes = MA.notes, isActive = MA.isActive, createDate = MA.createDate, updateDate = MA.updateDate, createUserId = MA.createUserId, updateUserId = MA.updateUserId, agentName = JAA.name, medalName = JMM.name, createUserName = JUU.username, } ).Select(c => new MedalAgentModel() { }) .ToList(); /* * * id * medalId * agentId * offerId * couponId * notes * isActive * createDate * updateDate * createUserId * updateUserId * */ // can delet or not if (medalsList == null) { return(NotFound()); } else { return(Ok(medalsList)); } } } //else return(NotFound()); }