Beispiel #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();
        }
Beispiel #2
0
 public static Computer RequestComputerToComputerDto(AddComputerDto addComputerDto)
 {
     return(new Computer
     {
         Guid = Guid.NewGuid().ToString(),
         Name = addComputerDto.Name,
         Description = addComputerDto.Description,
         Price = addComputerDto.Price,
         ImageFilename = addComputerDto.ImageFilename
     });
 }
Beispiel #3
0
 public static void ValidateRequestComputerDto(AddComputerDto addComputerDto)
 {
     if (string.IsNullOrEmpty(addComputerDto.Name))
     {
         throw new Exception("Computer Name cannot be null or empty");
     }
     if (string.IsNullOrEmpty(addComputerDto.Description))
     {
         throw new Exception("Computer Description cannot be null or empty");
     }
     if (string.IsNullOrEmpty(addComputerDto.ImageFilename))
     {
         throw new Exception("Computer Filename cannot be null or empty");
     }
     if (addComputerDto.Price < 0)
     {
         throw new Exception("Computer price cannot be negative");
     }
 }