public CommonSearchView <BranchView> SearchBranch(BranchSearchView model) { using (var ctx = new ConXContext()) { //define model view CommonSearchView <BranchView> view = new ModelViews.CommonSearchView <ModelViews.BranchView>() { pageIndex = model.pageIndex, itemPerPage = model.itemPerPage, totalItem = 0, datas = new List <ModelViews.BranchView>() }; //query data List <Branch> branches = ctx.Branchs .Include("branchGroup") .Where(x => (x.branchCode.Contains(model.branchDesc) || x.branchNameThai.Contains(model.branchDesc)) && x.entityCode.Contains(model.entityCode) && (x.branchGroupId == model.branchGroupId || model.branchGroupId == 0) //&& (model.branchGroupId.Contains(x.branchGroupId) || model.branchGroupId.Count == 0) && (model.status.Contains(x.status) || model.status.Count == 0) ) .OrderBy(o => o.branchCode) .ToList(); //count , select data from pageIndex, itemPerPage view.totalItem = branches.Count; branches = branches.Skip((view.pageIndex - 1) * view.itemPerPage) .Take(view.itemPerPage) .ToList(); //prepare model to modelView foreach (var i in branches) { view.datas.Add(new ModelViews.BranchView() { branchId = i.branchId, branchCode = i.branchCode, branchName = i.branchNameThai, branchGroupId = i.branchGroupId, branchGroupCode = i.branchGroup.branchGroupCode, branchGroupName = i.branchGroup.branchGroupName, status = i.status, statusTxt = i.statusTxt, entityCode = i.entityCode, docRunningPrefix = i.docRunningPrefix, }); } //return data to contoller return(view); } }
public HttpResponseMessage postSearchBranchId(BranchSearchView model) { try { var result = orgSvc.SearchBranchById(model); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString())); } }
public HttpResponseMessage postSearchBranch(BranchSearchView model) { try { model.branchDesc = model.branchDesc.Trim(); model.entityCode = model.entityCode.Trim(); var result = orgSvc.SearchBranch(model); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString())); } }