Exemple #1
0
        public async Task <bool> UpdateUserEmail(int id, string email)
        {
            var Id    = Guard.Argument(id, nameof(id)).NotNegative();
            var Email = Guard.Argument(email, nameof(email)).NotEmpty().NotNull().NotWhiteSpace();

            _context.Users.Update(new User()
            {
                UserId = Id, Email = Email
            });

            var isSaved = await _context.SaveChangesAsync();

            return(isSaved != 0);
        }
        public async Task <bool> UpdateClientData(ClientUpdateDto client, int clientId)
        {
            var Client   = Guard.Argument(client, nameof(client)).NotNull().Value;
            var ClientId = Guard.Argument(clientId, nameof(clientId)).NotNegative();


            var clientDb = await _context.Clients.SingleOrDefaultAsync(x => x.ClientId == ClientId);

            clientDb.Name     = Client.Name ?? clientDb.Name;
            clientDb.Address  = Client.Address ?? clientDb.Address;
            clientDb.City     = Client.City ?? clientDb.City;
            clientDb.NIP      = Client.NIP == null && Client.NIP == "" ? clientDb.NIP : Client.NIP;
            clientDb.PostCode = Client.PostCode != null?int.Parse(Client.PostCode) : clientDb.PostCode;

            clientDb.State = Client.State ?? clientDb.State;

            _context.Clients.Update(clientDb);

            var isSaved = await _context.SaveChangesAsync();

            return(isSaved != 0);
        }
        public async Task <UserConfirmedRegistation> RegisterNewUser(AuthRegisterForm authRegisterForm)
        {
            var UserRegisterForm = Guard.Argument(authRegisterForm, nameof(authRegisterForm)).NotNull().Value;
            var user             = new User()
            {
                Email    = UserRegisterForm.Email,
                Password = PasswordHasher(UserRegisterForm.Password),
                Role     = "Client"
            };

            _context.Users.Add(user);

            var client = new Client()
            {
                UserId   = user.UserId,
                Address  = UserRegisterForm.Address,
                City     = UserRegisterForm.City,
                Name     = UserRegisterForm.Name,
                PostCode = int.Parse(UserRegisterForm.PostCode),
                State    = UserRegisterForm.State,
                NIP      = UserRegisterForm.NIP == "" && UserRegisterForm.NIP == null ? null : UserRegisterForm.NIP
            };

            _context.Clients.Add(client);


            if (await _context.SaveChangesAsync() != 0)
            {
                return(new UserConfirmedRegistation()
                {
                    Login = user.Email
                });
            }

            throw new HttpStatusCodeException(HttpStatusCode.InternalServerError, _localizer["User couldn't be registered"]);
        }