public IHttpActionResult GetGroupMaxPages([FromUri] BaseApiParameterModel param) { try { int maxcount = 0; int maxpages = 0; IQueryable <MakerModel> query; query = dbContext.MakerModels.OrderBy(x => x.Id); if (!param.Deleted) { query = query.Where(x => x.Deleted == false); } if (param.Enabled) { query = query.Where(x => x.Enabled == true); } maxcount = query.Count(); if (param.Limit.HasValue) { maxpages = (int)(maxcount / (int)param.Limit); if ((int)(maxcount % (int)param.Limit) > 0) { maxpages += 1; } } return(Ok(new { count = maxcount, pages = maxpages })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult GetGroupList(int id, [FromUri] BaseApiParameterModel param) { try { if (id <= 0) { return(BadRequest(Messages.ApiIllegalParameter)); } List <GroupApiModel> result; IQueryable <GroupModel> query; query = dbContext.GroupModels.Where(g => g.MakerModelId == id); if (!param.Deleted) { query = query.Where(g => g.Deleted == false); } result = query.OrderBy(g => g.Id).ProjectTo <GroupApiModel>().ToList(); //if (result == null || result.Count == 0) // return NotFound(); return(Ok(result)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task <IHttpActionResult> GetRoleList(int id, [FromUri] BaseApiParameterModel param) { try { if (id <= 0) { return(BadRequest(Messages.ApiIllegalParameter)); } IList <string> roleList = await UserManager.GetRolesAsync(id); if (roleList == null) { return(NotFound()); } if (!User.IsInRole("admin")) { roleList = roleList.Where(rl => rl != "admin").ToList(); } return(Ok(roleList)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Get([FromUri] BaseApiParameterModel param) { try { List <ContainerApiModel> result; IQueryable <ContainerModel> query; query = dbContext.ContainerModels.OrderBy(x => x.Id); if (!param.Deleted) { query = query.Where(x => x.Deleted == false); } if (param.Limit.HasValue) { if (param.Page.HasValue) { query = query.Skip((int)param.Limit * (int)param.Page).Take((int)param.Limit); } else { query = query.Take((int)param.Limit); } } result = query.ProjectTo <ContainerApiModel>().ToList(); // if (result == null || result.Count == 0) // return NotFound(); return(Ok(result)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult GetHoliday([FromUri] BaseApiParameterModel param) { int year = DateTime.Now.Year; if (param.Page.HasValue) { year = (int)param.Page; } HolidayService service = new HolidayService(); return(Ok(service.getHoliday(year))); }
public IHttpActionResult GetLoginUser([FromUri] BaseApiParameterModel param) { string id = string.Empty; string name = string.Empty; try { id = User.Identity.GetUserId(); name = ((ClaimsIdentity)User.Identity).FindFirst(Models.UserModel.ApplicationClaimTypes.ClaimUserName).Value; } catch (Exception) { } WriteAppLog("Accounts", "取得"); return(Ok(new [] { new { Id = id, Name = name } })); }
public IHttpActionResult GetMakerList(int id, [FromUri] BaseApiParameterModel param) { try { if (id <= 0 || UserManager.FindById(id) == null) { return(BadRequest(Messages.ApiIllegalParameter)); } IList <MakerApiModel> makerList = dbContext.UserMakerModels .Where(um => um.UserModelId == id).Where(um => um.Deleted == false) .Select(um => um.MakerModel).OrderBy(m => m.Id).ProjectTo <MakerApiModel>().ToList(); return(Ok(makerList)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Get(int id, [FromUri] BaseApiParameterModel param) { try { if (id <= 0) { return(BadRequest(Messages.ApiIllegalParameter)); } GroupApiModel result = dbContext.GroupModels.Where(x => x.Id == id) .ProjectTo <GroupApiModel>().SingleOrDefault(); if (result == null) { return(NotFound()); } return(Ok(result)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Get(int id, [FromUri] BaseApiParameterModel param) { try { if (id <= 0) { return(BadRequest(Messages.ApiIllegalParameter)); } RoleModel model; model = dbContext.RoleModels.Where(x => x.Id == id).SingleOrDefault(); if (model == null) { return(NotFound()); } RoleApiModel result = Mapper.Map <RoleApiModel>(model); return(Ok(result)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Get([FromUri] BaseApiParameterModel param) { try { List <RoleApiModel> result; IQueryable <RoleModel> query; query = dbContext.RoleModels.OrderBy(r => r.Id); if (!User.IsInRole("admin")) { query = query.Where(r => r.Name != "admin"); } if (!param.Deleted) { query = query.Where(r => r.Deleted == false); } result = query.ProjectTo <RoleApiModel>().ToList(); return(Ok(result)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult GetProductList(int id, [FromUri] BaseApiParameterModel param) { try { if (id <= 0) { return(BadRequest(Messages.ApiIllegalParameter)); } if (dbContext.GroupModels.Where(g => g.Id == id).SingleOrDefault() == null) { return(BadRequest(Messages.ApiIllegalParameter)); } IList <ProductApiModel> groupList = dbContext.GroupProductModels .Where(um => um.GroupModelId == id).Where(um => um.Deleted == false) .Select(um => um.ProductModel).OrderBy(m => m.Id).ProjectTo <ProductApiModel>().ToList(); return(Ok(groupList)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task <IHttpActionResult> Get(int id, [FromUri] BaseApiParameterModel param) { try { if (id <= 0) { return(BadRequest(Messages.ApiIllegalParameter)); } UserModel user = await UserManager.FindByIdAsync(id); if (user == null) { return(NotFound()); } UserApiModel result = Mapper.Map <UserApiModel>(user); return(Ok(result)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public bool GetRole(string role, [FromUri] BaseApiParameterModel param) { WriteAppLog("Accounts/Roles/" + role, "取得"); return(User.IsInRole(role)); }
public IEnumerable <string> GetRoleList([FromUri] BaseApiParameterModel param) { WriteAppLog("Accounts/Roles", "取得"); return(UserManager.GetRoles(GetUserId())); }
public IHttpActionResult GetSalesViews(int id, int year, [FromUri] BaseApiParameterModel param) { return(StatusCode(HttpStatusCode.MethodNotAllowed)); }