Exemplo n.º 1
0
        public async Task <ActionResult <UserVM> > CreateDataAsync(CreateVM value)
        {
            try
            {
                // VALIDATE PASSWORD COMPLEXITY
                var passwordMessages = this.ValidatePassword(value.Password);
                if (passwordMessages.Length != 0)
                {
                    return(this.WarningResponse(passwordMessages));
                }

                // VALIDATE DUPLICITY [use this columns so we use the index]
                if (await this.dbContext.Users
                    .Where(x =>
                           x.RowStatus != (short)Base.enRowStatus.Removed &&
                           x.UserName == value.UserName &&
                           x.PasswordHash != "")
                    .CountAsync() != 0)
                {
                    return(this.WarningResponse(this.GetTranslation("USERS_USER_NAME_ALREADY_EXISTS_WARNING")));
                }

                // NEW MODEL
                var data = new UserData()
                {
                    UserName  = value.UserName,
                    Text      = value.Description,
                    JoinDate  = DateTime.Now,
                    RowStatus = (short)Base.enRowStatus.Temporary
                };

                // HASH THE PASSWORD
                var cryptService = this.GetService <Helpers.Crypt>();
                data.PasswordHash = cryptService.Encrypt(value.Password);

                // APPLY
                data.UserID = System.Guid.NewGuid().ToString();
                await this.dbContext.Users.AddAsync(data);

                await this.dbContext.SaveChangesAsync();

                // SEND ACTIVATION MAIL
                await this.SendActivationMailAsync(data.UserID);

                // RESULT
                var result = UserVM.Convert(data);
                return(this.CreatedResponse("users", result.UserID, result));
            }
            catch (Exception ex) { return(this.ExceptionResponse(ex)); }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <UserVM> > CreateDataAsync([FromBody] CreateVM value)
        {
            var service = this.GetService <UsersService>();

            return(await service.CreateDataAsync(value));
        }