//添加好友分组 public bool addGroup(Model.Group group) { int result = groupDal.addGroup(group); if (result == 1) { return(true); } else { return(false); } }
//添加好友分组 public int addGroup(Model.Group group) { string sql = "insert into [group] ([u_id],[name]) values (@UId,@Name)"; List <SqlParameter> parameters = new List <SqlParameter>(); SqlParameter UId = new SqlParameter("@UId", SqlDbType.Int); SqlParameter Name = new SqlParameter("@Name", SqlDbType.VarChar, 50); UId.Value = group.UId; parameters.Add(UId); Name.Value = group.Name; parameters.Add(Name); int result = SqlDbHelper.ExecuteNoQuery(sql, CommandType.Text, parameters); return(result); }
public void DeattachGroup(Group group, string userName) { Users user = this.ObjectContext.Users.First(x => x.UserName == userName); Group groupEntity = this.ObjectContext.Group.First(x => x.Id == group.Id); user.Groups.Attach(groupEntity); user.Groups.Remove(groupEntity); //this.ObjectContext.SaveChanges(); this.ObjectContext.AddToPermissionLog(CreateLog(string.Format("Odobraná používateľská rola {0}",groupEntity.Name), 2, user.Id)); this.ObjectContext.SaveChanges(); }
public void AttachGroupGroup(Group group, string userName) { Users user = this.ObjectContext.Users.First(x => x.UserName == userName); user.Groups.Add(this.ObjectContext.Group.First(x => x.Id == group.Id)); // this.ObjectContext.SaveChanges(); this.ObjectContext.AddToPermissionLog(CreateLog(string.Format("Pridaná používateľská rola {0}",group.Name ), 1, user.Id)); this.ObjectContext.SaveChanges(); }
public IList<Group> GetAllGroups() { var list = new List<Group>(); foreach (DataRow row in this["Group"].Rows) { var item = new Group { Id = (Guid)row["Id"], Name = (string)row["Name"], ShortName = row["ShortName"] == DBNull.Value ? null : row["ShortName"].ToString(), Description = row["Description"] == DBNull.Value ? null : row["Description"].ToString(), IsEnabled = (int)row["IsEnabled"], Etag = (byte[])row["Etag"], SortCode = (int)row["SortCode"], CategoryCode = row["CategoryCode"] == DBNull.Value ? null : row["CategoryCode"].ToString(), TypeCode = (string)row["TypeCode"] }; var entity = item as IEntityBase; entity.CreateBy = row["CreateBy"] == DBNull.Value ? null : row["CreateBy"].ToString(); entity.CreateOn = row["CreateOn"] == DBNull.Value ? null : (DateTime?)row["CreateOn"]; entity.CreateUserId = row["CreateUserId"] == DBNull.Value ? null : (Guid?)row["CreateUserId"]; entity.ModifiedBy = row["ModifiedBy"] == DBNull.Value ? null : row["ModifiedBy"].ToString(); entity.ModifiedOn = row["ModifiedOn"] == DBNull.Value ? null : (DateTime?)row["ModifiedOn"]; entity.ModifiedUserId = row["ModifiedUserId"] == DBNull.Value ? null : (Guid?)row["ModifiedUserId"]; list.Add(item); } return list; }
public void TestSmartCotnext_InsertGroupWithExistingRealtedUsers_AllShouldBeBackedUp() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineCountBefore = this.offlineContext.Users.Count(); int groupsInOfflineCountBefore = this.offlineContext.Groups.Count(); Group newGroup = new Group() { GroupId = 8888, Name = "NewGroup", Description = "New Group For Users" }; sCtx.Add(newGroup); sCtx.SaveChanges(); User existingUser = sCtx.GetSingle<User>(); newGroup.UsersInGroup.Add(existingUser); sCtx.SaveChanges(); int usersInOfflineCountAfter = this.offlineContext.Users.Count(); int groupsInOfflineCountAfter = this.offlineContext.Groups.Count(); IEnumerable<User> usersFromOfflineStorage = this.offlineContext.Users.Where(usr => usr.UserId == existingUser.UserId).ToList(); IEnumerable<Group> groupsFromOfflineStorage = this.offlineContext.Groups.Where(grp => grp.GroupId == newGroup.GroupId).ToList(); Assert.AreNotEqual(usersInOfflineCountBefore, usersInOfflineCountAfter); Assert.AreNotEqual(groupsInOfflineCountBefore, groupsInOfflineCountAfter); Assert.AreEqual(1, usersFromOfflineStorage.Count()); Assert.AreEqual(1, groupsFromOfflineStorage.Count()); } }
public void TestSmartCotnext_InsertGroupWithNewRealtedUsers_AllShouldBeBackedUp() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineCountBefore = this.offlineContext.Users.Count(); int groupsInOfflineCountBefore = this.offlineContext.Groups.Count(); Group newGroup = new Group() { GroupId = 8888, Name = "NewGroup", Description = "New Group For Users" }; User newUser = new User() { UserId = 1337, Name = "Mark", Email = "*****@*****.**", Note = "note note note", Income = 15543m }; newGroup.UsersInGroup.Add(newUser); sCtx.Add(newGroup); sCtx.SaveChanges(); int usersInOfflineCountAfter = this.offlineContext.Users.Count(); int groupsInOfflineCountAfter = this.offlineContext.Groups.Count(); IEnumerable<User> usersFromOfflineStorage = this.offlineContext.Users.Where(usr => usr.UserId == newUser.UserId).ToList(); IEnumerable<Group> groupsFromOfflineStorage = this.offlineContext.Groups.Where(grp => grp.GroupId == newGroup.GroupId).ToList(); Assert.AreNotEqual(usersInOfflineCountBefore, usersInOfflineCountAfter); Assert.AreNotEqual(groupsInOfflineCountBefore, groupsInOfflineCountAfter); Assert.AreEqual(1, usersFromOfflineStorage.Count()); Assert.AreEqual(1, groupsFromOfflineStorage.Count()); } }
protected static void SeedDatabase(FluentModel context) { User usr1 = new User() { UserId = 1, Name = "Gary Adkins", Note = "note note note", Email = "*****@*****.**", Income = 10000.324m }; User usr2 = new User() { UserId = 2, Name = "Tim Gordon", Note = "note note note", Email = "*****@*****.**", Income = 10000.324m }; User usr3 = new User() { UserId = 3, Name = "Jack Jameson", Note = "note note note", Email = "*****@*****.**", Income = 10000.324m }; User usr4 = new User() { UserId = 4, Name = "Bill Tompson", Note = "note note note", Email = "*****@*****.**", Income = 10000.324m }; Group administratorsGroup = new Group() { GroupId = 1, Name = "Administrators", Description = "admin group description", }; administratorsGroup.UsersInGroup.Add(usr1); administratorsGroup.UsersInGroup.Add(usr2); Group coreUsersGroup = new Group() { GroupId = 2, Name = "Core users", Description = "core users description" }; coreUsersGroup.UsersInGroup.Add(usr3); coreUsersGroup.UsersInGroup.Add(usr4); context.Add(administratorsGroup); context.Add(coreUsersGroup); context.SaveChanges(); }
public void TestSmartContext_InsertUsersWithNewRelatedGroup_AllShouldBeBackedUp() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineCountBefore = this.offlineContext.Users.Count(); int groupsInOfflineCountBefore = this.offlineContext.Groups.Count(); Group newGroup = new Group() { GroupId = 1227, Name = "New Group", Description = "Group of newness" }; User newUser1 = new User() { UserId = 1337, Name = "Mark", Email = "*****@*****.**", Note = "note note note", Income = 15543m }; newUser1.Group = newGroup; User newUser2 = new User() { UserId = 1338, Name = "Harry", Email = "*****@*****.**", Note = "note note note", Income = 12543m }; newUser2.Group = newGroup; sCtx.Add(newUser1); sCtx.Add(newUser2); sCtx.SaveChanges(); int usersInOfflineCountAfter = this.offlineContext.Users.Count(); int groupsInOfflineCountAfter = this.offlineContext.Groups.Count(); IEnumerable<User> usersFromOfflineStorage = this.offlineContext.Users.Where(usr => usr.UserId == newUser1.UserId || usr.UserId == newUser2.UserId).ToList(); IEnumerable<Group> groupsFromOfflineStorage = this.offlineContext.Groups.Where(grp => grp.GroupId == newGroup.GroupId).ToList(); Assert.AreNotEqual(usersInOfflineCountBefore, usersInOfflineCountAfter); Assert.AreNotEqual(groupsInOfflineCountBefore, groupsInOfflineCountAfter); Assert.AreEqual(2, usersFromOfflineStorage.Count()); Assert.AreEqual(1, groupsFromOfflineStorage.Count()); } }
public Model.Group Select(Model.Group Group) { try { SqlCommand cmd = new SqlCommand("Select * From [FAMIS].[dbo].[Group] Where group_id =" + Group.Group_id, db.Db()); SqlDataReader dr = cmd.ExecuteReader(); Model.Group Gp; Gp = new Model.Group(); while (dr.Read()) { if (!dr.IsDBNull(0)) { Gp.Name = dr.GetString(0); } if (!dr.IsDBNull(1)) { Gp.Agency_id = dr.GetInt32(1); } } return Gp; } catch (Exception ex) { throw new Exception(ex.Message); } }
//Nesse caso vai retornar uma lista de objeto. Não sei se seu retorno vão ter vários, ou um por vez. Se for um por vez, não precisa usar lista. public List<Model.Group> Select(String pWhere) { List<Model.Group> lstGroup = new List<Model.Group>(); Model.Group Gp; SqlCommand cmd = new SqlCommand("Select * From dbo.[Group] " + pWhere, db.Db()); //SQLHelper.ExecuteReader("string de conexao", CommandType.StoredProcedure, "Procedure", null) using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { Gp = new Model.Group(); if (!dr.IsDBNull(0)) { Gp.Group_id = dr.GetInt32(0); } if (!dr.IsDBNull(1)) { Gp.Name = dr.GetString(1); } if (!dr.IsDBNull(2)) { Gp.Agency_id = dr.GetInt32(2); } lstGroup.Add(Gp); } } return lstGroup; }
private void ReplaceToGroup(Group group) { if (SelectedUserTask != null) { var taskGroup = Groups.FirstOrDefault(p => p.Name == SelectedUserTask.Group); if (taskGroup != group) { group.UserTasks.Add(SelectedUserTask); if (!_undeleteGroups.Contains(taskGroup?.Name)) { taskGroup?.UserTasks.Remove(SelectedUserTask); } SelectedUserTask.Group = group.Name; } } }
public MainWindowViewModel() { var userTask1 = new UserTask { Description = "Купить молока, хлеба", DueDate = DateTime.Now.AddDays(-3), Name = "Сходить в магазин", TaskStatus = TaskStatus.New }; var userTask2 = new UserTask { Description = "Сходить на какой-нибудь фильм", DueDate = DateTime.Now.AddDays(-3), Name = "Посетить кинотеатр", TaskStatus = TaskStatus.New }; var userTask3 = new UserTask { Description = "Взять пылесос и почистить компьютер", DueDate = DateTime.Now.AddDays(1), Name = "ПОчисти компьютер", TaskStatus = TaskStatus.New }; var userTask4 = new UserTask { Description = "Убраться в комнате", DueDate = DateTime.Now.AddDays(1), Name = "СДелай влажную уборку в комнате", TaskStatus = TaskStatus.New }; var userTask5 = new UserTask { Description = "Съездить в институт", DueDate = DateTime.Now.AddDays(1), Name = "Посети институт", TaskStatus = TaskStatus.New }; var userTask6 = new UserTask { Description = "Поздравь с праздником", DueDate = DateTime.Now.AddDays(3), Name = "Поздравь с 8 марта всех знакомых девушек", TaskStatus = TaskStatus.New }; var group1 = new Group { Name = "Просроченые", UserTasks = new ObservableCollection<UserTask> {userTask1, userTask2}, }; var group2 = new Group { Name = "Истекают завтра", UserTasks = new ObservableCollection<UserTask> {userTask3, userTask4, userTask5}, }; var group3 = new Group { Name = "Мои задачи", UserTasks = new ObservableCollection<UserTask> { userTask1, userTask2, userTask3, userTask4, userTask5, userTask6 }, }; Groups = new ObservableCollection<Group> { group1, group2, group3 }; }
private void CreateNewGroup(object parameter) { SelectedGroup = new Group(); Groups.Add(SelectedGroup); ComboBoxGroups.Add(SelectedGroup); }