public async Task <GetOrganizationsResponse> GetAllAsync(GetOrganizationsRequest request) { var items = await _context.Organizations.ToListAsync(); return(new GetOrganizationsResponse { Items = items }); }
public GetOrganizationsResponse GetOrganizations(GetOrganizationsRequest getOrganizationsRequest) { GetOrganizationsResponse getOrganizationsResponse = new GetOrganizationsResponse(); List <Organization> organizations = new List <Organization>(); using (SqlConnection con = new SqlConnection(MWConnectionString)) { using (SqlCommand cmd = new SqlCommand("GetOrganizations", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@orgType", SqlDbType.VarChar, 20).Value = getOrganizationsRequest.orgType; cmd.Parameters.Add("@nameParm", SqlDbType.VarChar, 50).Value = getOrganizationsRequest.nameParm; cmd.Parameters.Add("@typeParm", SqlDbType.VarChar, 20).Value = getOrganizationsRequest.typeParm; cmd.Parameters.Add("@addressParm", SqlDbType.VarChar, 50).Value = getOrganizationsRequest.addressParm; cmd.Parameters.Add("@pageSize", SqlDbType.Int, 0).Value = getOrganizationsRequest.pageSize; cmd.Parameters.Add("@pageNumber", SqlDbType.Int, 0).Value = getOrganizationsRequest.pageNumber; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); int recordNumber = 1; while (reader.Read()) { if (recordNumber == 1) { getOrganizationsResponse.recordCount = Convert.ToInt32(reader["recordCount"].ToString()); } organizations.Add(new Organization { id = Convert.ToInt32(reader["ID"].ToString()), type = reader["Type"].ToString(), name = reader["Name"].ToString(), phone = reader["Phone"].ToString(), fax = reader["Fax"].ToString(), email = reader["Email"].ToString(), active = Convert.ToBoolean(reader["Active"].ToString()) }); } getOrganizationsResponse.organizations = organizations; } con.Close(); } return(getOrganizationsResponse); }
/// <summary> /// The GetOrganizations /// </summary> /// <param name="userToken">The userToken<see cref="UserToken"/></param> /// <param name="request">The request<see cref="GetOrganizationsRequest"/></param> /// <returns>The <see cref="Task{ResponseData{GetOrganizationsResponse}}"/></returns> public async Task <ResponseData <GetOrganizationsResponse> > GetOrganizations(UserToken userToken, GetOrganizationsRequest request) { try { var response = new ResponseData <GetOrganizationsResponse>(); if (userToken == null) { throw new UnauthorizedAccessException(); } var selfProfile = await _ctx.XUserInfo .Where(p => p.login == userToken.Id.ToString()) .AsNoTracking() .FirstOrDefaultAsync(); List <OrganizationItem> items = null; var selfuser = await _userManager.Users.FirstOrDefaultAsync(p => p.Id == userToken.Id); if (await _userManager.IsInRoleAsync(selfuser, MyIdentityRole.ROLE_SUPERADMIN)) { //items = await _ctx.moncli_info. // Select(p => new OrganizationItem(p)). // ToListAsync(); } else { //items = await _ctx.moncli_info. // Where(p => p.moncli_infoId == selfProfile.theClient ). // Select(p => new OrganizationItem(p)). // ToListAsync(); } response.code = BaseStatus.Success; response.data = new GetOrganizationsResponse() { Items = items }; return(response); } catch (Exception ex) { _logger.LogError(ex, "could not get organizations"); return(new ResponseData <GetOrganizationsResponse> { code = BaseStatus.Exception, message = "Ошибка", description = "Не удалось получить организации" }); } }
public async Task <GetOrganizationsResponse> GetAll(GetOrganizationsRequest request) { var organizationModel = new OrganizationModel(_context); return(await organizationModel.GetAllAsync(request)); }