/// <summary>
        /// Saves the user roles information.
        /// </summary>
        /// <param name="userRolesView">The user roles view.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">userRolesView</exception>
        public string SaveUserRolesInfo(IUserRolesView userRolesView)
        {
            if (userRolesView == null)
            {
                throw new ArgumentNullException(nameof(userRolesView));
            }

            var result    = string.Empty;
            var newRecord = new UserRole
            {
                RoleId = userRolesView.UserRolesId,

                DateCreated = DateTime.Now,
                Email       = userRolesView.Email,
            };

            using (
                var dbContext = (PitalyticsEntities)dbContextFactory.GetDbContext())
            {
                dbContext.UserRoles.Add(newRecord);
                dbContext.SaveChanges();
            }

            return(result);

            ;
        }
예제 #2
0
        /// <summary>
        /// Saves the user roles.
        /// </summary>
        /// <param name="userRolesView">The user roles view.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">userRolesView</exception>
        public string SaveUserRoles(IUserRolesView userRolesView)
        {
            var processingMessage = string.Empty;

            if (userRolesView == null)
            {
                throw new ArgumentNullException(nameof(userRolesView));
            }

            var result = this.accountRepository.SaveUserRolesInfo(userRolesView);

            //check for current roles

            var currentRoles = this.accountRepository.CheckCurrentRoles(userRolesView.Email, userRolesView.UserRolesId);

            if (currentRoles)
            {
                processingMessage = Messages.IsRolesExist;
                return(this.accountViewsModelFactory.CreateUserRolesView(processingMessage));
            }
            var userInfo = this.accountRepository.SaveUserRolesInfo(userRolesView);

            return(this.accountViewsModelFactory.CreateUserRolesView(userInfo));
        }