Example #1
0
        // POST: api/user
        public IHttpActionResult Post(HttpRequestMessage request, [FromBody] UserRoleModel value)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Executing call in debug mode");
            }

            var headers = request.Headers;

            //Check the request object to see if they passed a userId
            if (headers.Contains("userid"))
            {
                var user = headers.GetValues("userid").First();
                _log.InfoFormat("Handling POST request from user: {0}", user);

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                try
                {
                    UserRoleActions userRoleActions = new UserRoleActions();

                    userRoleActions.Insert(value, user);
                    return(Ok());
                }
                catch (Exception e)
                {
                    _log.Error("An error occurred while adding User.", e);
                    return(InternalServerError(e));
                }
            }

            return(BadRequest("Header value <userid> not found."));
        }
Example #2
0
        public IHttpActionResult Get(HttpRequestMessage request)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Executing call in debug mode");
            }

            var  headers      = request.Headers;
            bool showInActive = false;

            if (headers.Contains("showInactive"))
            {
                showInActive = Boolean.Parse(headers.GetValues("showInactive").First());
            }

            //Check the request object to see if they passed a userId
            if (headers.Contains("userid"))
            {
                var user = headers.GetValues("userid").First();
                _log.InfoFormat("Handling GET request from user: {0}", user);

                try
                {
                    UserRoleActions userRoleActions = new UserRoleActions();
                    _log.Debug("Getting User Roles");
                    IEnumerable <UserRoleModel> userRoleList = userRoleActions.Get(showInActive);
                    var userRoleModels = userRoleList as IList <UserRoleModel> ?? userRoleList.ToList();
                    _log.DebugFormat("User Roles retreived Count: {0}", userRoleModels.Count());
                    return(Ok(userRoleModels));
                }
                catch (Exception e)
                {
                    _log.Error("An error occurred while getting user Types.", e);
                    return(InternalServerError(e));
                }
            }

            return(BadRequest("Header value <userid> not found."));
        }
Example #3
0
        // GET: api/user/5
        public IHttpActionResult Get(int id, HttpRequestMessage request)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Executing call in debug mode");
            }

            var headers = request.Headers;

            //Check the request object to see if they passed a userId
            if (headers.Contains("userid"))
            {
                var user = headers.GetValues("userid").First();
                _log.InfoFormat("Handling GET request from user: {0}", user);

                UserRoleActions userRoleActions = new UserRoleActions();
                try
                {
                    _log.Debug("Getting userType");

                    var userRoleModel = userRoleActions.GetById(id);
                    if (userRoleModel != null)
                    {
                        _log.DebugFormat("User Role retrieved. ID: {0}", userRoleModel.Id);
                        return(Ok(userRoleModel));
                    }
                    return(Ok());
                }
                catch (Exception e)
                {
                    _log.Error("An error occurred while getting User Role.", e);
                    return(InternalServerError(e));
                }
            }
            return(BadRequest("Header value <userid> not found."));
        }
Example #4
0
        private static void SendNotification(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, UserRoleActions Action)
        {
            var objRoles = new RoleController();
            var Custom   = new ArrayList {
                objRole.RoleName, objRole.Description
            };

            switch (Action)
            {
            case UserRoleActions.add:
            case UserRoleActions.update:
                string preferredLocale = objUser.Profile.PreferredLocale;
                if (string.IsNullOrEmpty(preferredLocale))
                {
                    preferredLocale = PortalSettings.DefaultLanguage;
                }
                var          ci          = new CultureInfo(preferredLocale);
                UserRoleInfo objUserRole = objRoles.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
                Custom.Add(Null.IsNull(objUserRole.EffectiveDate)
                                   ? DateTime.Today.ToString("g", ci)
                                   : objUserRole.EffectiveDate.ToString("g", ci));
                Custom.Add(Null.IsNull(objUserRole.ExpiryDate) ? "-" : objUserRole.ExpiryDate.ToString("g", ci));
                break;

            case UserRoleActions.delete:
                Custom.Add("");
                break;
            }
            var _message = new Message
            {
                FromUserID = PortalSettings.AdministratorId,
                ToUserID   = objUser.UserID,
                Subject    =
                    Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings,
                                                  "EMAIL_ROLE_" +
                                                  UserRoleActionsCaption[(int)Action] +
                                                  "_SUBJECT", objUser),
                Body = Localization.GetSystemMessage(objUser.Profile.PreferredLocale,
                                                     PortalSettings,
                                                     "EMAIL_ROLE_" +
                                                     UserRoleActionsCaption[(int)Action] + "_BODY",
                                                     objUser,
                                                     Localization.GlobalResourceFile,
                                                     Custom),
                Status = MessageStatusType.Unread
            };

            //_messagingController.SaveMessage(_message);
            Mail.SendEmail(PortalSettings.Email, objUser.Email, _message.Subject, _message.Body);
        }
Example #5
0
        private static void SendNotification(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, UserRoleActions Action)
        {
            var objRoles = new RoleController();
            var Custom = new ArrayList {objRole.RoleName, objRole.Description};
            switch (Action)
            {
                case UserRoleActions.add:
                case UserRoleActions.update:
                    string preferredLocale = objUser.Profile.PreferredLocale;
                    if (string.IsNullOrEmpty(preferredLocale))
                    {
                        preferredLocale = PortalSettings.DefaultLanguage;
                    }
                    var ci = new CultureInfo(preferredLocale);
                    UserRoleInfo objUserRole = objRoles.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
                    Custom.Add(Null.IsNull(objUserRole.EffectiveDate)
                                   ? DateTime.Today.ToString("g", ci)
                                   : objUserRole.EffectiveDate.ToString("g", ci));
                    Custom.Add(Null.IsNull(objUserRole.ExpiryDate) ? "-" : objUserRole.ExpiryDate.ToString("g", ci));
                    break;
                case UserRoleActions.delete:
                    Custom.Add("");
                    break;
            }
            var _message = new Message
                               {
                                   FromUserID = PortalSettings.AdministratorId,
                                   ToUserID = objUser.UserID,
                                   Subject =
                                       Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings,
                                                                     "EMAIL_ROLE_" +
                                                                     UserRoleActionsCaption[(int) Action] +
                                                                     "_SUBJECT", objUser),
                                   Body = Localization.GetSystemMessage(objUser.Profile.PreferredLocale,
                                                                        PortalSettings,
                                                                        "EMAIL_ROLE_" +
                                                                        UserRoleActionsCaption[(int) Action] + "_BODY",
                                                                        objUser,
                                                                        Localization.GlobalResourceFile,
                                                                        Custom),
                                   Status = MessageStatusType.Unread
                               };

            //_messagingController.SaveMessage(_message);
            Mail.SendEmail(PortalSettings.Email, objUser.Email, _message.Subject, _message.Body);
        }