示例#1
0
        // Register is always used for someone not in the database, only first time User or first time Asset use this method
        public async Task<AccountResult> RegisterUser(RegistrationModelBase model)
        {
            UserProfile profile;
            User user = null;

            switch (model.Type)
            {
                case IdentityTypes.USER:
                    profile = new UserProfile(model as UserRegistrationModel);
                    user = new User(model as UserRegistrationModel, profile);
                    break;
                case IdentityTypes.BIKE_MESSENGER:
                case IdentityTypes.CNG_DRIVER:
                    profile = new AssetProfile(model as AssetRegistrationModel);
                    user = new Asset(model as AssetRegistrationModel, profile as AssetProfile);
                    break;
                case IdentityTypes.ENTERPRISE:
                    var enterpriseProfile = new EnterpriseUserProfile(model as EnterpriseUserRegistrationModel);
                    user = new EnterpriseUser(model as EnterpriseUserRegistrationModel, enterpriseProfile);
                    break;

            }
            var identityResult = await accountManager.CreateAsync(user, model.Password);
            var creationResult = new AccountResult(identityResult, user);

            return creationResult;
        }
示例#2
0
        public async Task<SendEmailResponse> NotifyUserCreationByMail(User user)
        {
            string code = await this.accountManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var clientSettings = Settings.Get<ClientSettings>();
            clientSettings.Validate();

            var confirmEmailRouteParams = new Dictionary<string, string>() { { "userId", user.Id }, { "code", code } };
            var confirmationUrl = string.Concat(clientSettings.WebCatUrl, clientSettings.ConfirmEmailPath, confirmEmailRouteParams.ToQuerystring());

            var result = await mailService.SendWelcomeMail(new SendWelcomeEmailRequest()
            {
                RecipientEmail = user.Email,
                RecipientUsername = user.UserName,
                ConfirmationUrl = confirmationUrl.ToString()
            });
            return result;
        }
示例#3
0
        public MethodResponse UpdateUserForWCF(User _user)
        {
            MethodResponse methodresponse = new MethodResponse();
            try
            {
                User user = UpdateUser(_user);
                methodresponse.Type = MethodResponse.ResponseType.Succeed;
                methodresponse.ResultText = "User Updated";
                methodresponse.Object = user;
            }
            catch (Exception ex)
            {
                CustomException custom_exception = new CustomException()
                {
                    Exception = ex,
                    ExceptionTime = DateTime.Now,
                    Parameters = "",
                    HelpLink = "",
                    User = "",
                    MethodName = "UpdateUserForWCF"
                };
                CustomExceptionDB custom_exceptionDB = new CustomExceptionDB();
                bool isSaved = custom_exceptionDB.SaveException(custom_exception);
                if (isSaved == true)
                {
                    //..
                }
                methodresponse.Object = null;
                methodresponse.Type = MethodResponse.ResponseType.Error;
                methodresponse.ResultText = "An Error Occurred While Updating User";



            }
            return methodresponse;
        }
示例#4
0
        public User UpdateUser(User _user)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    User olduser = context.Users.FirstOrDefault(c => c.UserId == _user.UserId);
                    if (olduser != null)
                    {
                        olduser.FirstName = _user.FirstName;
                        olduser.LastName = _user.LastName;
                        olduser.Password = _user.Password;
                        

                        context.SaveChanges();
                        return olduser;
                    }
                    return null;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
示例#5
0
        public User AddUser(User _user)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Users.Add(_user);

                    context.SaveChanges();
                    return _user;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }