Beispiel #1
0
        //
        // GET: /Group/Create
        public ActionResult Create()
        {
            Group objGroup = new Group();

            objGroup.Users = this.repository.Users(_userStatistics.OrganizationId);

            objGroup.OrganizationList = LoadSelectLists();
            objGroup.OrganizationId = ViewBag.OrganizationId == null ? 0 : Convert.ToInt32(ViewBag.OrganizationId);
            return View(objGroup);
        }
Beispiel #2
0
        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();
            }
        }
Beispiel #3
0
 public bool CreateGroup(Group objGroup)
 {
     var parameters = new
     {
         GroupName = objGroup.GroupName,
         Description = objGroup.Description,
         InsertedOn = objGroup.InsertedOn,
         InsertedBy = objGroup.InsertedBy,
         OrganizationId = objGroup.OrganizationId
     };
     using (IDbConnection connection = OpenConnection())
     {
         const string storedProcedure = "usp_AddGroups";
         int rowsAffected = connection.Execute(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
         SetIdentity<int>(connection, id => objGroup.GroupId = id);
         if (rowsAffected > 0)
         {
             return true;
         }
         return false;
     }
 }
Beispiel #4
0
        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();
            }
        }