public string Edit(Group objGroup) { try { if (ModelState.IsValid) { objGroup.ModifieBy = _userStatistics.UserId; objGroup.ModifiedOn = DateTime.Now; DBConnectionString.Group group = new DBConnectionString.Group { Description = objGroup.Description, GroupId = objGroup.GroupId, GroupName = objGroup.GroupName, ModifieBy = _userStatistics.UserId, ModifiedOn = DateTime.Now, OrganizationId = objGroup.OrganizationId, InsertedBy = objGroup.InsertedBy, InsertedOn = objGroup.InsertedOn }; UserGroup objUserGroup = null; int recAffected = group.Update(); if (recAffected > 0) { objGroup.UserGroups = this.repository.UserGroupsByGroup(objGroup.GroupId); if (objGroup.Members != null) { var userIds = objGroup.Members.Split(','); foreach (var id in userIds) { if (!objGroup.UserGroups.Select(s => s.UserId).Contains(Convert.ToInt64(id))) { objUserGroup = new UserGroup(); objUserGroup.UserId = Convert.ToInt32(id); objUserGroup.GroupId = objGroup.GroupId; objUserGroup.InsertedBy = _userStatistics.UserId; this.repository.AssignGroupToUser(objUserGroup); } } foreach (var ug in objGroup.UserGroups) { if (!userIds.Contains(ug.UserId.ToString())) { repository.DeleteUserGroup(ug.UserId, ug.GroupId); } } return(Convert.ToString(true)); } return(Convert.ToString(true)); } return(Convert.ToString(false)); } return(Convert.ToString(false)); } catch (Exception ex) { return(ex.Message.ToString()); } }
public string Edit(Group objGroup) { try { if (ModelState.IsValid) { objGroup.ModifieBy = _userStatistics.UserId; objGroup.ModifiedOn = DateTime.Now; DBConnectionString.Group group = new DBConnectionString.Group { Description = objGroup.Description, GroupId = objGroup.GroupId, GroupName = objGroup.GroupName, ModifieBy = _userStatistics.UserId, ModifiedOn = DateTime.Now, OrganizationId = objGroup.OrganizationId, InsertedBy=objGroup.InsertedBy, InsertedOn=objGroup.InsertedOn }; UserGroup objUserGroup = null; int recAffected = group.Update(); if (recAffected > 0) { objGroup.UserGroups = this.repository.UserGroupsByGroup(objGroup.GroupId); if (objGroup.Members != null) { var userIds = objGroup.Members.Split(','); foreach (var id in userIds) { if (!objGroup.UserGroups.Select(s => s.UserId).Contains(Convert.ToInt64(id))) { objUserGroup = new UserGroup(); objUserGroup.UserId = Convert.ToInt32(id); objUserGroup.GroupId = objGroup.GroupId; objUserGroup.InsertedBy = _userStatistics.UserId; this.repository.AssignGroupToUser(objUserGroup); } } foreach (var ug in objGroup.UserGroups) { if (!userIds.Contains(ug.UserId.ToString())) { repository.DeleteUserGroup(ug.UserId, ug.GroupId); } } return Convert.ToString(true); } return Convert.ToString(true); } return Convert.ToString(false); } return Convert.ToString(false); } catch (Exception ex) { return ex.Message.ToString(); } }