public void AddNewUserGroup(long userId, long groupId) { UserGroup objGroup = new UserGroup(); objGroup.UserId = userId; objGroup.GroupId = groupId; objGroup.InsertedBy = _userStatistics.UserId; this.repository.AssignGroupToUser(objGroup); }
public bool AddNewUserGroup(long userId, long? groupId, long? studentId) { UserGroup objUserGroup = new UserGroup(); objUserGroup.UserId = userId; objUserGroup.GroupId = Convert.ToInt32(groupId); objUserGroup.InsertedBy = _userStatistics.UserId; objUserGroup.StudentId = studentId; if (this.repository.AssignGroupToUser(objUserGroup)) { return true; } return false; }
public string Create(Group objGroup) { try { if (ModelState.IsValid) { objGroup.InsertedOn = DateTime.Now; objGroup.InsertedBy = _userStatistics.UserId; //objGroup.UserCount = objGroup.Members.Split(',').Length; UserGroup objUserGroup = null; if (repository.CreateGroup(objGroup)) { if (objGroup.Members != null) { var userIds = objGroup.Members.Split(','); foreach (var id in userIds) { objUserGroup = new UserGroup(); objUserGroup.UserId = Convert.ToInt32(id); objUserGroup.GroupId = objGroup.GroupId; objUserGroup.InsertedBy = _userStatistics.UserId; this.repository.AssignGroupToUser(objUserGroup); } return Convert.ToString(true); } return Convert.ToString(true); } return Convert.ToString(false); } return Convert.ToString(false); } catch (Exception ex) { return ex.Message.ToString(); } }
public bool AssignGroupToUser(UserGroup objUserGroup) { var parameters = new { UserId = objUserGroup.UserId, GroupId = objUserGroup.GroupId, InsertedOn = DateTime.Now, InsertedBy = objUserGroup.InsertedBy, StudentId = objUserGroup.StudentId, StaffId = objUserGroup.Default }; using (IDbConnection connection = OpenConnection()) { const string storedProcedure = "usp_AssignGroupToUser"; int rowsAffected = connection.Execute(storedProcedure, parameters, commandType: CommandType.StoredProcedure); SetIdentity<int>(connection, id => objUserGroup.GroupId = id); if (rowsAffected > 0) { return true; } return false; } }
private void AssignGroup(string groupIds, long userId) { if (groupIds != null) { var idList = groupIds.Split(','); UserGroup objUserGroup = null; foreach (var groupId in idList) { objUserGroup = new UserGroup(); objUserGroup.UserId = userId; objUserGroup.GroupId = Convert.ToInt32(groupId); objUserGroup.InsertedBy = _userStatistics.UserId; this.repository.AssignGroupToUser(objUserGroup); } } }
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(); } }