public void AddUserLog(int userId, string message)
 {
     var curr = _db.Users.Find(CurrUserId == 0 ? userId : CurrUserId);
     var log = new UserLog
     {
         Comment = message,
         ByUserId = CurrUserId,
         ByUserName = curr.FullName,
         UserId = userId
     };
     _db.UserLogs.Add(log);
     _db.SaveChanges();
 }
        public JsonResult Block(int id, UserRegisterStatus status, string reason)
        {
            if (status == UserRegisterStatus.Approved)
            {
                if (string.IsNullOrEmpty(reason))
                {

                    ModelState.AddModelError("", "Reason to block is required");
                }
                else if (reason.Length > 1000)
                {
                    ModelState.AddModelError("", "Length of reason to block cannot be more than 1000");
                }
            }
            if (ModelState.IsValid)
            {
                var user = _db.Users.Find(id);
                var log = new UserLog(CurrentUser, id);
                _db.UserLogs.Add(log);
                if (status == UserRegisterStatus.Suspended)
                {
                    user.AccountStatus = UserRegisterStatus.Approved;
                    log.Comment = Strings.UnblockedMsg;
                }
                else
                {
                    user.AccountStatus = UserRegisterStatus.Suspended;
                    log.Comment = "User Blocked. Reason: " + reason;
                }
                _db.SaveChanges();
            }
            return GetErrorMsgJSON();
        }
        public JsonResult UpdateUserRole(int id, UserRoleType role)
        {
            var user = _db.Users
                .Include(u => u.UserRoles)
                .Single(u => u.UserId == id);

            var uRole = user.UserRoles.First();
            uRole.RoleType = role;
            var log = new UserLog(CurrentUser, id)
                {
                    Comment = "Made " + uRole.RoleType.ToString()
                };
            _db.UserLogs.Add(log);
            _db.Entry(uRole).State = System.Data.EntityState.Modified;
            _db.SaveChanges();
            return GetErrorMsgJSON();
        }
 public JsonResult UpdateTouchPoint(int id)
 {
     var user = _db.Users.Find(id);
     user.IsTouchPoint = !user.IsTouchPoint;
     var log = new UserLog(CurrentUser, id);
     log.Comment = "Touch Point Status: " + user.IsTouchPoint;
     _db.UserLogs.Add(log);
     _db.SaveChanges();
     return GetErrorMsgJSON();
 }
        public JsonResult UpdateAdminRole(int id)
        {
            var user = _db.Users
                .Include(u => u.UserRoles)
                .Single(u => u.UserId == id);

            var adminRole = user.UserRoles.SingleOrDefault(u => u.RoleType == UserRoleType.Admin);
            var log = new UserLog(CurrentUser, id);
            _db.UserLogs.Add(log);
            if (adminRole != null)
            {
                if (user.UserRoles.Count == 1)
                {
                    var role = new UserRole
                    {
                        RoleType = UserRoleType.Guest,
                        UserId = id,
                    };
                    _db.UserRoles.Add(role);
                }
                _db.Entry(adminRole).State = System.Data.EntityState.Deleted;
                log.Comment = Strings.RemovedAdmin;
            }
            else
            {
                var role = new UserRole
                {
                    RoleType = UserRoleType.Admin,
                    UserId = id,
                };
                _db.UserRoles.Add(role);
                log.Comment = Strings.AddedAdmin;
            }
            _db.SaveChanges();
            return GetErrorMsgJSON();
        }