示例#1
0
        internal async Task ById(SearchByIdModel model, SqlConnection connection1, UsersByIdModel resultSeachByIdModel, bool isAdmin)
        {
            resultSeachByIdModel.email       = "";
            resultSeachByIdModel.firstname   = "";
            resultSeachByIdModel.lastname    = "";
            resultSeachByIdModel.direccion   = "";
            resultSeachByIdModel.colonia     = "";
            resultSeachByIdModel.ciudad      = "";
            resultSeachByIdModel.tel         = "";
            resultSeachByIdModel.menu        = new List <GroupsUsersByIdMenuDetailsModel>();
            resultSeachByIdModel.groups      = new List <GroupsUsersByIdGroupsDetailsModel>();
            resultSeachByIdModel.isrootadmin = Convert.ToInt32(isAdmin);
            bool save = true;

            if (model.id != "0")
            {
                if (!isAdmin)
                {
                    save = await CheckisAdmin(connection1, model.id);
                }
                if (save)
                {
                    await GetById(connection1, model, resultSeachByIdModel);
                }
            }
            if (save)
            {
                await GetByMenu(connection1, model, resultSeachByIdModel);
                await GetByGroups(connection1, model, resultSeachByIdModel);
            }
        }
示例#2
0
 internal async Task ById(SearchByIdModel model, SqlConnection connection1, CompaniesByIdModel resultSeachByIdModel)
 {
     resultSeachByIdModel.name  = "";
     resultSeachByIdModel.users = new List <CompaniesUsersByIdDetailsModel>();
     if (model.id != "0")
     {
         await GetById(connection1, model, resultSeachByIdModel);
     }
     await GetByUsers(connection1, model, resultSeachByIdModel);
 }
示例#3
0
 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);
 }
示例#4
0
        private async Task GetByUsers(SqlConnection connection1, SearchByIdModel model, CompaniesByIdModel 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 companiesusers g on g.idcompany = @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())
            {
                CompaniesUsersByIdDetailsModel details = new CompaniesUsersByIdDetailsModel();
                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();
        }
示例#5
0
        private async Task GetById(SqlConnection connection1, SearchByIdModel model, UsersByIdModel data)
        {
            SqlCommand cmd = new SqlCommand();

            string cmdString = "SELECT a.email, isnull(u.firstname,''), isnull(u.lastname,''), isnull(u.direccion,''), isnull(u.colonia,''), isnull(u.ciudad,''), isnull(u.tel,''), u.photo, " +
                               "r.name FROM AspNetUsers as a " +
                               "left join users u on a.id = u.id " +
                               "left join AspNetUserRoles ur on a.id = ur.UserId " +
                               "left join AspNetRoles r on ur.RoleId = r.id " +
                               "where a.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.email     = reader.GetString(0);
                data.firstname = reader.GetString(1);
                data.lastname  = reader.GetString(2);
                data.direccion = reader.GetString(3);
                data.colonia   = reader.GetString(4);
                data.ciudad    = reader.GetString(5);
                data.tel       = reader.GetString(6);
                if (reader.IsDBNull(7))
                {
                    data.photo = new byte[0];
                }
                else
                {
                    data.photo = (byte[])reader["photo"];
                }
                if (!reader.IsDBNull(8))
                {
                    data.isadmin = 1;
                }
            }
            reader.Close();
        }
示例#6
0
        private async Task GetByGroups(SqlConnection connection1, SearchByIdModel model, UsersByIdModel data)
        {
            SqlCommand cmd = new SqlCommand();

            string cmdString = "select m.id, m.name, g.ischecked from groups m " +
                               "left join usersgroups g on m.id = g.idgroup and g.iduser = @id  " +
                               "left join users gr on g.iduser = gr.id and gr.id = @id " +
                               "where m.status = 1 " +
                               "order by m.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.ischecked = false;
                    details.isEdit    = 0;
                }
                else
                {
                    details.ischecked = reader.GetBoolean(2);
                    details.isEdit    = 1;
                }
                data.groups.Add(details);
            }
            reader.Close();
        }
示例#7
0
        private async Task GetById(SqlConnection connection1, SearchByIdModel model, CompaniesByIdModel data)
        {
            SqlCommand cmd = new SqlCommand();

            string cmdString = "SELECT name FROM Companies " +
                               "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();
        }
示例#8
0
        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();
        }
示例#9
0
文件: Menu.cs 项目: jelz2ykmx/demoapp
 internal async Task ById(SearchByIdModel model, SqlConnection connection1, MenuByIdModel resultSeachByIdModel)
 {
     await GetById(connection1, model, resultSeachByIdModel);
 }
示例#10
0
        internal async Task <SearchByIdModel> New(UsersUpdateModel model, HttpRequestMessage Request, string connetionString, bool isAdmin, string idAdminrole)
        {
            SearchByIdModel idUser = new SearchByIdModel();

            var appDbContext = Request.GetOwinContext().Get <ApplicationDbContext>();

            using (var identitydbContextTransaction = appDbContext.Database.BeginTransaction())
            {
                var UserManager = Request.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var userByEmail = await UserManager.FindByEmailAsync(model.email);

                if (userByEmail == null)
                {
                    var user = new ApplicationUser()
                    {
                        UserName = model.email, Email = model.email
                    };
                    if (model.menu.Count > 0 || model.groups.Count > 0)
                    {
                        user.PhoneNumberConfirmed = true;
                    }

                    IdentityResult result = await UserManager.CreateAsync(user, model.password);

                    if (!result.Succeeded)
                    {
                        ErrorModel _errors = new ErrorModel();
                        foreach (string error in result.Errors)
                        {
                            _errors.message += error;
                        }
                        throw new Exception(_errors.message);
                    }
                    else
                    {
                        using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                        {
                            using (SqlConnection connection1 = new SqlConnection(connetionString))
                            {
                                idUser.id = user.Id;
                                model.id  = user.Id;
                                await connection1.OpenAsync();
                                await SaveUser(connection1, model);

                                if (model.isUserAdmin == 0)
                                {
                                    foreach (var item in model.menu)
                                    {
                                        await SaveUsersMenu(connection1, model.id, item);
                                    }
                                    foreach (var item in model.groups)
                                    {
                                        await SaveUsersGroups(connection1, model.id, item);
                                    }
                                }
                                else if (isAdmin && idAdminrole != null && idAdminrole != "")
                                {
                                    await AddAdminRole(connection1, model.id, idAdminrole);
                                }
                                scope.Complete();
                                identitydbContextTransaction.Commit();
                                return(idUser);
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Correo ya existe");
                }
            }
        }