예제 #1
0
        /// <summary>
        /// Saves the user application role.
        /// </summary>
        /// <param name="userDetail">The user detail.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">userDetail</exception>
        public string SaveUserAppRole(IUserAppRoleView userDetail)
        {
            if (userDetail == null)
            {
                throw new ArgumentNullException(nameof(userDetail));
            }

            string result = string.Empty;

            var newRecord = new UserAppRole
            {
                Username         = userDetail.Username,
                AppRoleId        = userDetail.AppRoleId,
                DateCreated      = DateTime.UtcNow,
                CreateByUsername = userDetail.CreateByUsername
            };

            try
            {
                using (
                    var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS))
                {
                    dbContext.UserAppRoles.Add(newRecord);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result = string.Format("SaveRegistrationInfo - {0} , {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }

            return(result);
        }
예제 #2
0
 public bool DeleteUserAppRole(long id)
 {
     try
     {
         UserAppRole UserAppRole = PSF.Get <UserAppRole>(id);
         PSF.Delete <UserAppRole>(UserAppRole);
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #3
0
        /// <summary>
        /// Creates the user role.
        /// </summary>
        /// <param name="registrationInfo">The registration information.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">registrationInfo</exception>
        public string CreateUserRole(IRegistrationView registrationInfo)
        {
            if (registrationInfo == null)
            {
                throw new ArgumentNullException(nameof(registrationInfo));
            }

            var result    = string.Empty;
            var newRecord = new UserAppRole
            {
                Username         = registrationInfo.Username,
                DateCreated      = DateTime.Now,
                CreateByUsername = registrationInfo.Username
            };

            if (registrationInfo.SelectedRole == "CompanyAdmin")
            {
                newRecord.AppRoleId = 5; //CompanyAdmin
            }

            if (registrationInfo.SelectedRole == "Employee")
            {
                newRecord.AppRoleId = 2; //Employee
            }

            try
            {
                using (
                    var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS))
                {
                    dbContext.UserAppRoles.Add(newRecord);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result = string.Format("CreateUserRole - {0} , {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }


            return(result);
        }
예제 #4
0
 public long CreateOrUpdateUserAppRole(UserAppRole userapprole)
 {
     try
     {
         if (userapprole != null)
         {
             PSF.SaveOrUpdate <UserAppRole>(userapprole);
         }
         else
         {
             throw new Exception("userapprole is required and it cannot be null..");
         }
         return(userapprole.Id);
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #5
0
 public ActionResult AddUserAppRole(UserAppRole apm, string test)
 {
     try
     {
         string userId = base.ValidateUser();
         if (string.IsNullOrWhiteSpace(userId))
         {
             return(RedirectToAction("LogOn", "Account"));
         }
         else
         {
             UserService aps = new UserService();
             Dictionary <string, object> criteria = new Dictionary <string, object>();
             criteria.Add("UserId", apm.UserId);
             criteria.Add("AppCode", apm.AppCode);
             criteria.Add("RoleCode", apm.RoleCode);
             criteria.Add("SectorCode", apm.SectorCode);
             Dictionary <long, IList <UserAppRole> > userapprole = aps.GetAppRoleForAnUserListWithPagingAndCriteria(null, null, null, null, criteria);
             if (test == "edit")
             {
                 if (userapprole != null && userapprole.First().Value != null && userapprole.First().Value.Count > 1)
                 {
                     return(null); //return Json("false"); //throw new Exception("The given region is already exists!");
                 }
                 else
                 {
                     if (apm.RoleCode == "CSE")
                     {
                         apm.ContingentCode = null;
                     }
                     apm.RoleName = "nil";
                     apm.AppName  = "nil";
                     ViewBag.flag = 1;
                     aps.CreateOrUpdateUserAppRole(apm);
                     return(null);
                 }
             }
             else
             {
                 if (userapprole != null && userapprole.First().Value != null && userapprole.First().Value.Count > 0)
                 {
                     var script1 = @"ErrMsg(""This Combination already exists"");";
                     return(JavaScript(script1));
                 }
                 else
                 {
                     if (apm.RoleCode == "CSE")
                     {
                         apm.ContingentCode = null;
                     }
                     apm.AppName  = "depart";
                     apm.RoleName = "role";
                     aps.CreateOrUpdateUserAppRole(apm);
                     var script = @"SucessMsg(""Role mapped Sucessfully"");";
                     return(JavaScript(script));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }