internal async Task ById(SearchByIdModel model, SqlConnection connection1, GroupsByIdModel resultSeachByIdModel) { resultSeachByIdModel.name = ""; resultSeachByIdModel.menu = new List <GroupsUsersByIdMenuDetailsModel>(); resultSeachByIdModel.users = new List <GroupsUsersByIdGroupsDetailsModel>(); if (model.id != "0") { await GetById(connection1, model, resultSeachByIdModel); } await GetByMenu(connection1, model, resultSeachByIdModel); await GetByUsers(connection1, model, resultSeachByIdModel); }
private async Task GetById(SqlConnection connection1, SearchByIdModel model, GroupsByIdModel data) { SqlCommand cmd = new SqlCommand(); string cmdString = "SELECT name FROM Groups " + "where id = @id"; cmd.CommandText = cmdString; cmd.Connection = connection1; SqlParameter parameter = new SqlParameter("@id", SqlDbType.VarChar); parameter.Value = model.id; cmd.Parameters.Add(parameter); SqlDataReader reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { data.name = reader.GetString(0); } reader.Close(); }
private async Task GetByUsers(SqlConnection connection1, SearchByIdModel model, GroupsByIdModel data) { SqlCommand cmd = new SqlCommand(); string cmdString = "select a.id, a.email, u.firstName + ' ' + u.LastName as name, g.ischecked from AspNetUsers a " + "left join users u on a.id = u.id " + "left join usersgroups g on g.idgroup = @id and g.iduser = u.id " + "left join AspNetUserRoles ur on a.id = ur.UserId " + "left join AspNetRoles r on ur.RoleId = r.id " + "where a.LockoutEnabled = 0 and r.name is null " + "order by name"; cmd.CommandText = cmdString; cmd.Connection = connection1; SqlParameter parameter = new SqlParameter("@id", SqlDbType.VarChar); parameter.Value = model.id; cmd.Parameters.Add(parameter); SqlDataReader reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { GroupsUsersByIdGroupsDetailsModel details = new GroupsUsersByIdGroupsDetailsModel(); details.id = reader.GetString(0); details.name = reader.GetString(1); if (!reader.IsDBNull(2)) { details.name = reader.GetString(2).Trim(); } if (reader.IsDBNull(3)) { details.ischecked = false; details.isEdit = 0; } else { details.ischecked = reader.GetBoolean(3); details.isEdit = 1; } data.users.Add(details); } reader.Close(); }
private async Task GetByMenu(SqlConnection connection1, SearchByIdModel model, GroupsByIdModel data) { SqlCommand cmd = new SqlCommand(); string cmdString = "select m.id, m.menu, g.isquery, g.isedit, g.isnew, g.isdelete from menu m " + "left join groupsmenu g on m.id = g.idmenu and g.idgroup = @id " + "left join groups gr on g.idgroup = gr.id and gr.id = @id " + "where m.status = 1 " + "order by m.menu"; cmd.CommandText = cmdString; cmd.Connection = connection1; SqlParameter parameter = new SqlParameter("@id", SqlDbType.VarChar); parameter.Value = model.id; cmd.Parameters.Add(parameter); SqlDataReader reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { GroupsUsersByIdMenuDetailsModel details = new GroupsUsersByIdMenuDetailsModel(); details.id = reader.GetString(0); details.name = reader.GetString(1); details.isEdit = 0; if (reader.IsDBNull(2)) { details.isquery = 0; } else { details.isquery = reader.GetInt32(2); details.isEdit = 1; } if (reader.IsDBNull(3)) { details.iseditField = 0; } else { details.iseditField = reader.GetInt32(3); details.isEdit = 1; } if (reader.IsDBNull(4)) { details.isnew = 0; } else { details.isnew = reader.GetInt32(4); details.isEdit = 1; } if (reader.IsDBNull(5)) { details.isdelete = 0; } else { details.isdelete = reader.GetInt32(5); details.isEdit = 1; } data.menu.Add(details); } reader.Close(); }
public async Task <HttpResponseMessage> Groups(GroupsDataModel model) { Thread.CurrentThread.CurrentCulture = culture; List <GroupsQueryModel> resultSeachModel = null; GroupsByIdModel resultSeachByIdModel = null; Grupos proxy = new Grupos(); try { if (!await Authentication.isAdmin(User, Request)) { Authentication auth = new Authentication(); if (!await auth.AccesRights(User.Identity.GetUserId(), "groups", model.type)) { return(Request.CreateResponse(System.Net.HttpStatusCode.Unauthorized)); } auth = null; } using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { using (SqlConnection connection1 = new SqlConnection(connetionString)) { await connection1.OpenAsync(); if (model.type == 1) { resultSeachModel = new List <GroupsQueryModel>(); await proxy.SearchQuery(model.search, resultSeachModel, connection1); } else if (model.type == 2) { resultSeachByIdModel = new GroupsByIdModel(); await proxy.ById(model.byId, connection1, resultSeachByIdModel); } else if (model.type == 3) { await proxy.New(connection1, model.update); } else if (model.type == 4) { await proxy.Update(connection1, model.update); } else if (model.type == 5) { await proxy.UpdateIsActive(connection1, model.isActive); } } scope.Complete(); } } catch (TransactionAbortedException ex) { ErrorModel _errors = new ErrorModel(); _errors.message = ex.Message; return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors)); } catch (Exception ex) { ErrorModel _errors = new ErrorModel(); _errors.message = ex.Message; return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, _errors)); } if (model.type == 1) { return(Request.CreateResponse(System.Net.HttpStatusCode.OK, resultSeachModel)); } else if (model.type == 2) { return(Request.CreateResponse(System.Net.HttpStatusCode.OK, resultSeachByIdModel)); } return(Request.CreateResponse(System.Net.HttpStatusCode.OK)); }