public IHttpActionResult GetCompanies([FromUri] PagingParameterModel paging) { if (paging.PageNumber <= 0) { return(BadRequest()); } else { var Companies = CompanyContext.Companies.Where(c => c.IsDeleted == false) .OrderBy(u => u.Name) .AsQueryable() .Skip((paging.PageNumber - 1) * paging.PageSize) .Take(paging.PageSize) .Include(c => c.userID) .Include(c => c.IndustryType) .ToList(); //.Include(c => c.IndustryType) List <CompanyViewPublicModel> Models = new List <CompanyViewPublicModel>(); foreach (Company Company in Companies) { CompanyViewPublicModel Model = new CompanyViewPublicModel(); Model.Id = Company.Id; Model.Name = Company.Name; Model.Nip = Company.Nip; Model.Address = Company.Address; Model.City = Company.City; ApplicationUser userID = Company.userID; Model.userID = userID.Id.ToString(); if (Company.IndustryType != null) { Model.IdustryName = Company.IndustryType.Name; Model.IndustryId = Company.IndustryType.Id; } else { Model.IdustryName = null; Model.IndustryId = null; } Models.Add(Model); } return(Ok(Models)); } }
public IHttpActionResult GetCompaniesByIndustry(int IndustryId) { //int IndustryId = 2; Industry CurrentIndustry = CompanyContext.Industries.SingleOrDefault(i => i.Id == IndustryId); if (CurrentIndustry == null) { return(NotFound()); } else { var Companies = CompanyContext.Companies.Where(c => c.IsDeleted == false) .Where(c => c.IndustryType.Id == IndustryId) .Include(c => c.userID) .Include(c => c.IndustryType) .ToList(); //.Include(c => c.IndustryType) List <CompanyViewPublicModel> Models = new List <CompanyViewPublicModel>(); foreach (Company Company in Companies) { CompanyViewPublicModel Model = new CompanyViewPublicModel(); Model.Id = Company.Id; Model.Name = Company.Name; Model.Nip = Company.Nip; Model.Address = Company.Address; Model.City = Company.City; ApplicationUser userID = Company.userID; Model.userID = userID.Id.ToString(); Model.IdustryName = Company.IndustryType.Name; Model.IndustryId = Company.IndustryType.Id; Models.Add(Model); } return(Ok(Models)); } }
public IHttpActionResult GetCompany(int Id) { var Company = CompanyContext.Companies.Include(c => c.userID) .Include(c => c.IndustryType) .SingleOrDefault(c => c.Id == Id); if (Company == null || Company.IsDeleted == true) { return(NotFound()); } else { CompanyViewPublicModel Model = new CompanyViewPublicModel(); Model.Id = Company.Id; Model.Name = Company.Name; Model.Nip = Company.Nip; Model.Address = Company.Address; Model.City = Company.City; ApplicationUser userID = Company.userID; Model.userID = userID.Id.ToString(); if (Company.IndustryType != null) { Model.IdustryName = Company.IndustryType.Name; Model.IndustryId = Company.IndustryType.Id; } else { Model.IdustryName = null; Model.IndustryId = null; } return(Ok(Model)); } }
// GET: Company/1 public async Task <ActionResult> Company(int Id) { CompanyViewPublicModel Company = null; HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync("api/Company/" + Id.ToString()); if (response.StatusCode == HttpStatusCode.Unauthorized) { return(View("Unauthorized")); } if (response.StatusCode == HttpStatusCode.NotFound) { return(View("NotFound")); } if (response.IsSuccessStatusCode) { Company = await response.Content.ReadAsAsync <CompanyViewPublicModel>(); return(View(Company)); } else { return(View("SomethingWrong")); } }