コード例 #1
0
        public void AddComputer(AddComputerDto addComputerDto)
        {
            AuthenticationService.AuthenticateRoot(_username, _password);
            ValidationService.ValidateRequestComputerDto(addComputerDto);
            Computer computer = TransformationService.RequestComputerToComputerDto(addComputerDto);
            var      entities = DatabaseContext.GetEntities();

            entities.Computers.Add(computer);
            entities.Save();
        }
コード例 #2
0
        public UserInfoDto GetUser(string userId)
        {
            AuthenticationService.AuthenticateRoot(_username, _password);
            User user = QueryService.FindUserById(userId);

            if (user == null)
            {
                throw new Exception("User not found. Id: " + userId);
            }
            return(TransformationService.UserToUserInfoDto(user));
        }
コード例 #3
0
        public void DeleteOrder(string orderId)
        {
            AuthenticationService.AuthenticateRoot(_username, _password);
            Order order = QueryService.FindOrder(orderId);

            if (order == null)
            {
                throw new Exception("Order not found. Id: " + orderId);
            }
            Entities entities = DatabaseContext.GetEntities();

            entities.Orders.Remove(order);
            entities.Save();
        }
コード例 #4
0
        public void DeleteComputer(string computerId)
        {
            AuthenticationService.AuthenticateRoot(_username, _password);
            Computer computer = QueryService.FindComputerByGuid(computerId);

            if (computer == null)
            {
                throw new Exception("Computer not found. Id: " + computerId);
            }
            Entities entities = DatabaseContext.GetEntities();

            entities.Computers.Remove(computer);
            entities.Save();
        }
コード例 #5
0
        public void DeleteUser(string userId)
        {
            AuthenticationService.AuthenticateRoot(_username, _password);
            User user = QueryService.FindUserById(userId);

            if (user == null)
            {
                throw new Exception("User not found. Id: " + userId);
            }
            Entities entities = DatabaseContext.GetEntities();

            entities.Users.Remove(user);
            entities.Save();
        }
コード例 #6
0
        public void UpdateComputer(string computerId, UpdateComputerDto updateComputerDto)
        {
            AuthenticationService.AuthenticateRoot(_username, _password);
            ValidationService.ValidateUpdateComputerDto(updateComputerDto);
            Computer computer = QueryService.FindComputerByGuid(computerId);

            if (computer == null)
            {
                throw new Exception("Computer not found. Id: " + computerId);
            }
            computer.Name          = updateComputerDto.Name;
            computer.Description   = updateComputerDto.Description;
            computer.Price         = updateComputerDto.Price;
            computer.ImageFilename = updateComputerDto.ImageFilename;
            DatabaseContext.GetEntities().Save();
        }
コード例 #7
0
        public NewUserIdDto CreateUser(NewUserDto newUserDto)
        {
            AuthenticationService.AuthenticateRoot(_username, _password);
            ValidationService.ValidatedNewUserDto(newUserDto);
            if (QueryService.FindUserByUsername(newUserDto.Username) != null)
            {
                throw new Exception("Cannot create user. Username is duplicate. Username: " + newUserDto.Username);
            }
            User     user     = TransformationService.NewUserDtoToUser(newUserDto);
            Entities entities = DatabaseContext.GetEntities();

            entities.Users.Add(user);
            entities.Save();
            return(new NewUserIdDto {
                Id = user.Guid
            });
        }
コード例 #8
0
        public void UpdateUser(string userId, UpdateUserDto updatedUserDto)
        {
            AuthenticationService.AuthenticateRoot(_username, _password);
            ValidationService.ValidateUpdateUserDto(updatedUserDto);
            User user = QueryService.FindUserById(userId);

            if (user == null)
            {
                throw new Exception("User not found. Id: " + userId);
            }
            user.Name     = updatedUserDto.Name;
            user.Surname  = updatedUserDto.Surname;
            user.Email    = updatedUserDto.Email;
            user.Password = EncryptionService.HashPassword(updatedUserDto.Password);
            user.Username = updatedUserDto.Username;
            user.IsRoot   = updatedUserDto.IsRoot;
            DatabaseContext.GetEntities().Save();
        }