Example #1
0
        /// <summary>
        /// Adds the specified user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns></returns>
        /// <exception cref="BadRequestException">The username is already in use</exception>
        public UserWithTokenModel Add(RegisterModel entity)
        {
            User user = new User()
            {
                Email         = entity.Email,
                FirstName     = entity.FirstName,
                LastName      = entity.LastName,
                Password      = entity.Password.Encrypt(),
                PhoneNumber   = entity.PhoneNumber,
                IsDeleted     = entity.IsDeleted,
                PremiumStatus = false
            };

            var username = user.Email.Trim();

            if (GetQuery().Any(u => u.Email == username))
            {
                throw new BadRequestException("The username is already in use");
            }

            AddUserRoles(user, user.Roles);
            m_IRegisterRepository.Add(user);

            return(GetAUthenticate(entity.Email, entity.Password));
        }
        /// <summary>
        /// The Save
        /// </summary>
        /// <param name="entity">The entity<see cref="Register"/></param>
        /// <returns>The <see cref="ServiceResult"/></returns>
        public ServiceResult Save(Register entity)
        {
            try
            {
                if (entity.Identifier.Equals(""))
                {
                    _repository.Add(entity);
                }
                else
                {
                    _repository.Update(entity);
                }

                return(new ServiceResult(true));
            }
            catch (Exception ex)
            {
                return(new ServiceResult(false)
                {
                    Error = ex.ToString()
                });
            }
        }