예제 #1
0
        public ApiResponse Add(User info)
        {
            try
            {
                var validator = new UserRegistrtionValidator();
                var result    = validator.Validate(info);

                if (result.IsValid)
                {
                    info.Password = StringCipher.Encrypt(info.Password, passPhrase);
                    info.Status   = NUserStatus.Active.GetStrValue();
                    info.Token    = Guid.NewGuid().ToString();

                    if (dacMgr.Insert(info))
                    {
                        logMgr.Info("Register new an user " + info.Email);


                        var emailMgr = new EmailMgr();

                        if (emailMgr.SendRegConfirmEmail(info))
                        {
                            response.Success = true;
                        }
                        else
                        {
                            logMgr.Error(info.Email + " failed to send a registration email");
                        }
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        response.ErrorList.Add(new Error {
                            Message = error.PropertyName + error.ErrorMessage
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.ErrorList.Add(new Error {
                    Message = "Internal Server Error Code:500"
                });

                logMgr.Error(ex);
            }

            return(response);
        }
예제 #2
0
        public ApiResponse Add(User info)
        {
            try
            {
                var validator = new UserRegistrtionValidator();
                var result = validator.Validate(info);

                if (result.IsValid)
                {
                    info.Password = StringCipher.Encrypt(info.Password, passPhrase);
                    info.Status = NUserStatus.Active.GetStrValue();
                    info.Token = Guid.NewGuid().ToString();

                    if (dacMgr.Insert(info))
                    {
                        logMgr.Info("Register new an user " + info.Email);


                        var emailMgr = new EmailMgr();

                        if (emailMgr.SendRegConfirmEmail(info))
                            response.Success = true;
                        else
                            logMgr.Error(info.Email + " failed to send a registration email");
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        response.ErrorList.Add(new Error { Message = error.PropertyName + error.ErrorMessage });
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.ErrorList.Add(new Error { Message = "Internal Server Error Code:500" });

                logMgr.Error(ex);
            }

            return response;
        }