Exemple #1
0
        /// <summary>
        /// Get user.
        /// </summary>
        /// <param name="id">user id</param>
        /// <returns>user details</returns>
        public IEditUserVM GetEditUserVM(int?id)
        {
            var _editUserData = _kernel.Get <IEditUserVM>();

            if (id != null && id != 0)
            {
                IPersonnelObject po = GetUserInfo(id.GetValueOrDefault());
                if (po != null)
                {
                    _editUserData.isExists      = true;
                    _editUserData.selectedTitle = _editUserData.GetValue(po.Title, _editUserData.TitleOptions);
                    _editUserData.International = _editUserData.GetValue(po.International, _editUserData.YesNoOptions);
                    _editUserData.Resigned      = _editUserData.GetValue(po.Resigned, _editUserData.YesNoOptions);
                    _editUserData.UserID        = po.UserID.ToString();
                    _editUserData.Grade         = _editUserData.GetValue(po.Grade, _editUserData.GradeOptions);
                    _editUserData.AdminRights   = _editUserData.GetValue(po.AdminRights, _editUserData.AdminRightsOptions);
                    _editUserData.DateLeft      = po.DateLeft;
                    _editUserData.DateResigned  = po.DateResigned;
                    _editUserData.EmailAddress  = po.EmailAddress;
                    _editUserData.FirstName     = po.FirstName;
                    _editUserData.LastName      = po.LastName;
                    _editUserData.Initials      = po.Initials;
                    _editUserData.Office        = po.Office;
                    _editUserData.IsNew         = false;
                    _editUserData.UserName      = po.UserName;
                    _editUserData.Department    = po.Department;
                    _editUserData.IsEmail       = po.isEmailNotification;
                    _editUserData.PageTitle     = "Edit User";
                }
                else
                {
                    _editUserData.PageTitle = "Edit User";
                    _editUserData.isExists  = false;
                    _editUserData.IsNew     = false;
                }
            }
            else if (id == null)
            {
                _editUserData.isExists  = true;
                _editUserData.UserID    = "(New User : Id not yet generated)";
                _editUserData.IsNew     = true;
                _editUserData.PageTitle = "Add User";
            }

            return(_editUserData);
        }
Exemple #2
0
        /// <summary>
        /// Save user info.
        /// </summary>
        /// <param name="po">Personnel Object</param>
        /// <param name="isnew">is new flag</param>
        /// <param name="modifiedUser">modified user</param>
        /// <returns>user id</returns>
        public int SaveUserInfo(IPersonnelObject po, bool isnew, string modifiedUser)
        {
            if (isnew)
            {
                var newuserrecord = new Amdox.DataModel.User();
                newuserrecord.IsEnabled       = true;
                newuserrecord.IsAllowedToVote = true;

                this.dataContext.Users.Add(newuserrecord);
                this.dataContext.SaveChanges();
                po.UserID = newuserrecord.UserID;
            }

            var userdata           = this.dataContext.Users.FirstOrDefault(x => x.UserID == po.UserID);
            var userdetailsolddata = this.dataContext.UserDetails.FirstOrDefault(x => x.UserID == po.UserID && x.IsDeleted == false);
            var userdetailsdata    = new Amdox.DataModel.UserDetail();

            if (userdetailsolddata != null)
            {
                userdetailsolddata.IsDeleted = true;
                userdetailsdata.IsEmailNotificationRequired = userdetailsolddata.IsEmailNotificationRequired;
            }

            userdata.Initial    = po.Initials;
            userdata.Department = po.Department;
            userdata.UserName   = po.UserName;

            userdetailsdata.FirstName                   = po.FirstName;
            userdetailsdata.LastName                    = po.LastName;
            userdetailsdata.ResignationDate             = po.DateResigned;
            userdetailsdata.DateLeft                    = po.DateLeft;
            userdetailsdata.EmailAddress                = po.EmailAddress;
            userdetailsdata.OfficeLocation              = po.Office;
            userdetailsdata.Title                       = po.Title;
            userdetailsdata.CreatedDate                 = DateTime.Now;
            userdetailsdata.CreatedBy                   = this.GetUserID(modifiedUser);
            userdetailsdata.UserID                      = po.UserID;
            userdetailsdata.IsDeleted                   = false;
            userdetailsdata.IsEmailNotificationRequired = po.isEmailNotification;

            if (po.Grade == "A")
            {
                userdetailsdata.PartnerTypeID = 1;
            }
            else if (po.Grade == "B")
            {
                userdetailsdata.PartnerTypeID = 2;
            }
            else
            {
                userdetailsdata.PartnerTypeID = null;
            }

            if (po.AdminRights == "Y")
            {
                userdetailsdata.UserTypeID = 1;
            }
            else if (po.AdminRights == "S")
            {
                userdetailsdata.UserTypeID = 2;
            }
            else
            {
                userdetailsdata.UserTypeID = 3;
            }

            if (po.International == "Y")
            {
                userdetailsdata.IsInternationalPartner = true;
            }
            else
            {
                userdetailsdata.IsInternationalPartner = false;
            }

            if (po.Resigned == "Y")
            {
                userdetailsdata.isResigned = true;
                userdata.IsAllowedToVote   = false;
            }
            else
            {
                userdetailsdata.isResigned = false;
            }

            this.dataContext.UserDetails.Add(userdetailsdata);
            this.dataContext.SaveChanges();

            return(po.UserID);
        }