internal async Task New(SqlConnection connection1, GroupsUpdateModel model) { await SaveGroup(connection1, model); foreach (var item in model.menu) { await SaveGroupMenu(connection1, model.id, item); } List <string> users = new List <string>(); int counter = model.menu.Count; foreach (var item in model.users) { await SaveGroupsUsers(connection1, model.id, item); if (counter > 0) { users.Add(item.iduser); } } if (users.Count > 0) { await UpdateAspNetUser(connection1, users); } }
private async Task UpdateGroup(SqlConnection connection1, GroupsUpdateModel model) { String commandText1 = "update Groups set name = @name " + "where id = @id"; SqlCommand command1 = new SqlCommand(commandText1, connection1); SqlParameter parameter = new SqlParameter("@id", SqlDbType.VarChar); parameter.Value = model.id; command1.Parameters.Add(parameter); parameter = new SqlParameter("@name", SqlDbType.VarChar); parameter.Value = model.name; command1.Parameters.Add(parameter); await command1.ExecuteNonQueryAsync(); }
private async Task SaveGroup(SqlConnection connection1, GroupsUpdateModel model) { String commandText1 = "INSERT INTO Groups " + "(id,name,status) " + "values (@id,@name,1)"; SqlCommand command1 = new SqlCommand(commandText1, connection1); SqlParameter parameter = new SqlParameter("@id", SqlDbType.VarChar); parameter.Value = model.id; command1.Parameters.Add(parameter); parameter = new SqlParameter("@name", SqlDbType.VarChar); parameter.Value = model.name; command1.Parameters.Add(parameter); await command1.ExecuteNonQueryAsync(); }