Esempio n. 1
0
        private void AddPet()
        {
            var pet = _petService.GetPetInstance();

            Console.Write("Type a Pet name");
            pet.Name = Console.ReadLine();
            Console.WriteLine("Type Race");
            pet.Type = Console.ReadLine();
            Console.WriteLine("Type the color");
            pet.Color = Console.ReadLine();


            pet.SoldDate = DateTime.Now;
            Console.WriteLine("Type the sale price");
            double price;

            while (!double.TryParse(Console.ReadLine(), out price) ||
                   price > 5000000 ||
                   price < 10)
            {
                Console.WriteLine("Please select a number between 10.000 - 5.000.000");
            }


            var petAdded = _petService.Create(pet);

            if (petAdded.Id > 0)
            {
                Console.WriteLine("Pet has been added");
            }
        }
Esempio n. 2
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IPetService service = testServer.Host.Services.GetService(typeof(IPetService)) as IPetService;
            var         model   = new ApiPetServerRequestModel();

            model.SetProperties(1, 2, "B", 2);
            CreateResponse <ApiPetServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.PetDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiPetServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
        public ActionResult <Pet> Post([FromBody] Pet pet)
        {
            if (string.IsNullOrEmpty(pet.Name) || pet.PetType == null || pet.PetColor == null || pet.SoldDate == null || string.IsNullOrEmpty(pet.previousOwner))
            {
                return(BadRequest("Error, Error, Error! Check Everything you typed in. Error!"));
            }
            if (pet.Price <= 0 || pet.Price.Equals(null))
            {
                return(BadRequest("Error, Error, Error! Check the Price, Moron. Error!"));
            }

            PetType petType = pet.PetType;

            if (petType.ID == 0)
            {
                if (string.IsNullOrEmpty(petType.NameOfPetTypes))
                {
                    return(BadRequest("Really? Want another explanation?! Fine! You did not enter all information for a new petType, moron!"));
                }
            }

            Owner owner = pet.PetOwner;

            if (owner.ID == 0)
            {
                if (string.IsNullOrEmpty(owner.FirstName) || string.IsNullOrEmpty(owner.LastName) || string.IsNullOrEmpty(owner.Address) || string.IsNullOrEmpty(owner.PhoneNumber) || string.IsNullOrEmpty(owner.Email))
                {
                    return(BadRequest("You did not enter all the required owner data, pal. Enter the id of an existing owner, or EXIT!!!!"));
                }
            }

            _petService.Create(pet);
            return(StatusCode(500, $"Yay Pet" + pet.Name + $"has been bred"));
        }
Esempio n. 4
0
        public void WebScraping()
        {
            List <Pets> result = new List <Pets>();

            var webClient = new WebClient();
            var html      = webClient.DownloadString("https://www.adoptapet.com/index.html");

            var parser   = new HtmlParser();
            var document = parser.ParseDocument(html);

            var data = document.QuerySelector(".results_wrapper");

            var eachData = data.QuerySelectorAll(".pet_results");

            foreach (var onedata in eachData)
            {
                Pets pet = new Pets();
                pet.ImageUrl    = onedata.QuerySelector("img").GetAttribute("src");
                pet.Title       = onedata.QuerySelector("p:nth-child(2)").TextContent.Trim();
                pet.Location    = onedata.QuerySelector("p:nth-child(3)").TextContent.Trim();
                pet.Description = onedata.QuerySelector("a:nth-child(4)").TextContent;


                //  calling insert service to insert to db
                int addPet = _petService.Create(pet);
            }
        }
        public IActionResult Post([FromBody] Pets pet)
        {
            var result = _petService.Create(pet);

            return(new ObjectResult(result)
            {
                StatusCode = StatusCodes.Status201Created
            });
        }
Esempio n. 6
0
        public ActionResult <Pet> Post([FromBody] Pet pet)
        {
            if (string.IsNullOrEmpty(pet.Name))
            {
                return(BadRequest("A name is required for creating a pet"));
            }

            return(_petService.Create(pet));
        }
Esempio n. 7
0
        private void CreatePet()
        {
            // todo: input check + exception handling

            Console.WriteLine("Create new pet:\n");
            var petToCreate = AskPetDetails();
            var pet         = _petService.Create(petToCreate);

            Console.WriteLine($"Pet with Id: {pet.Id} is created");
        }
Esempio n. 8
0
        public override async Task <ActionResult <PetResponse> > HandleAsync(CreatePetRequest request)
        {
            var petCreated = await _petService.Create(request.Name, request.AnimalId, request.EmployeeId);

            if (petCreated is null)
            {
                return(NotFound());
            }

            return(PetResponse.FromPetDTO(petCreated));
        }
Esempio n. 9
0
 public ActionResult Post([FromBody] Pet pet)
 {
     try
     {
         return(Ok(_petService.Create(pet)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Esempio n. 10
0
        public IHttpActionResult Create(Pet pet)
        {
            if (ModelState.IsValid)
            {
                var petDto = _mapper.Map <PetDto>(pet);
                _petService.Create(petDto);

                return(Ok());
            }

            return(BadRequest(ModelState));
        }
Esempio n. 11
0
 public ActionResult <Pet> Post([FromBody] Pet pet)
 {
     try
     {
         Pet petCreated = _petService.Create(pet);
         return(Created($"Pet with id {petCreated.Id} was created.", petCreated));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
Esempio n. 12
0
 public ActionResult <Pet> Post([FromBody] Pet pet)
 {
     try
     {
         _petService.Create(pet);
         return(StatusCode(201, $"Yes Sir! Pet {pet.Name} created"));
     }
     catch (System.Exception)
     {
         return(StatusCode(500, "Error when creating pet"));
     }
 }
Esempio n. 13
0
        public ActionResult <PetResponse> Create([FromBody] PetRequest petRequest)
        {
            var pet = _petService.Create(petRequest as Pet);

            return(new PetResponse
            {
                Id = pet.Id,
                Nome = pet.Nome,
                Tipo = pet.Tipo,
                Raca = pet.Raca,
                Idade = pet.Idade,
            });
        }
Esempio n. 14
0
        public async Task <PetResponse> Create([FromBody] PetRequest petRequest)
        {
            var pet = await _petService.Create(petRequest as Pet);

            return(new PetResponse
            {
                Id = pet.Id,
                Nome = pet.Nome,
                Tipo = pet.Tipo,
                Raca = pet.Raca,
                Idade = pet.Idade,
            });
        }
Esempio n. 15
0
        public void startUI()
        {
            Pet pet = new Pet()
            {
                Id        = 50,
                Name      = "Warner",
                Type      = AnimalType.RABBIT,
                BirthDate = DateTime.Parse("11/29/2011"),
                SoldDate  = DateTime.Parse("07/30/2012"),
                Price     = 275
            };

            _petService.Create(pet);
        }
Esempio n. 16
0
        public ActionResult <Pet> Post([FromBody] Pet pet)
        {
            if (string.IsNullOrEmpty(pet.Name))
            {
                return(BadRequest("Error, Error, Error! Check Name. Error!"));
            }

            if (pet.Price <= 0 || pet.Price.Equals(null))
            {
                return(BadRequest("Error, Error, Error! Check the Price, Moron. Error!"));
            }
            _petService.Create(pet);
            return(StatusCode(500, $"Yay Pet" + pet.Name + $"has been bred"));
        }
Esempio n. 17
0
        private void CreatePet()
        {
            Console.WriteLine("-Add-");
            Console.WriteLine("Choose animal:");
            AnimalType type = SelectAnimalType();

            Console.WriteLine("Name:");
            string name = Console.ReadLine();

            Console.WriteLine();
            Console.WriteLine("Birthdate:");
            Console.WriteLine("format(dd/mm/yyyy)");
            DateTime birthdate;

            while (!DateTime.TryParseExact(Console.ReadLine(), "d/M/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out birthdate))
            {
                ConsoleError();
            }
            Console.WriteLine();
            Console.WriteLine("Sold date:");
            Console.WriteLine("format(dd/mm/yyyy)");
            DateTime soldDate;

            while (!DateTime.TryParseExact(Console.ReadLine(), "d/M/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out soldDate))
            {
                ConsoleError();
            }
            Console.WriteLine();
            Console.WriteLine("Color:");
            string color = Console.ReadLine();

            Console.WriteLine();
            Console.WriteLine("Previous owner:");
            Owner previousOwner = null;

            Console.WriteLine();
            Console.WriteLine("Price:");
            double price;

            while (!Double.TryParse(Console.ReadLine(), out price))
            {
                ConsoleError();
            }
            Console.WriteLine();
            Pet pet = petService.New(name, type, birthdate, soldDate, previousOwner, price);

            petService.Create(pet);
            ClearPetList();
            ShowPetListData(petService.ReadAll().List.ToList());
        }
Esempio n. 18
0
        public ActionResult <Pet> Post([FromBody] Pet value)
        {
            Pet pet = value;

            /*if (string.IsNullOrEmpty(pet.name))
             * {
             *  return BadRequest("Name is required for creating Pet");
             * }
             *
             * if (string.IsNullOrEmpty(pet.previousowner))
             * {
             *  return BadRequest("Previous owner is required for creating Pet");
             * }*/
            return(_petService.Create(pet));
        }
Esempio n. 19
0
 public ActionResult Post([FromBody] Pet pet)
 {
     try
     {
         var createResult = _petService.Create(pet);
         if (createResult.Id > 0)
         {
             return(StatusCode(201, createResult));
         }
         return(StatusCode(500, "Ops Action failed"));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, $"Process failed!!??:( Exception Message:{ex.Message}"));
     }
 }
Esempio n. 20
0
 public ActionResult <Pet> Post([FromBody] Pet pet)
 {
     if (string.IsNullOrEmpty(pet.Name))
     {
         return(BadRequest("missing Name"));
     }
     if (string.IsNullOrEmpty(pet.Color))
     {
         return(BadRequest("missing colour"));
     }
     if (pet.Price <= 0 || pet.Price.Equals(null))
     {
         return(BadRequest("invalid Price input"));
     }
     _petService.Create(pet);
     return(StatusCode(500, $" Pet {pet.Name} created successfully"));
 }
Esempio n. 21
0
        public async Task <IActionResult> Create(Pet petModel)
        {
            var userId = _userManager.GetUserId(HttpContext.User);

            if (ModelState.IsValid)
            {
                _petService.Create(
                    petModel.PetAge,
                    petModel.PetDifficulty,
                    petModel.PetName,
                    petModel.PetWeight,
                    petModel.PetType,
                    petModel.PetBreed,
                    userId
                    );
                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Esempio n. 22
0
        public IHttpActionResult Post(Models.Pet pet)
        {
            Database.Entities.Pet dbPet = new Database.Entities.Pet()
            {
                ID          = Guid.NewGuid(),
                Adopted     = pet.Adopted,
                Name        = pet.Name,
                ImageUrl    = pet.ImageUrl,
                Description = pet.Description,
                BirthDate   = pet.BirthDate,
                Breed       = pet.Breed,
                FurType     = pet.FurType,
                Location    = pet.Location,
                MainColour  = pet.MainColour,
                PureBreed   = pet.PureBreed,
                Size        = pet.Size,
                Species     = pet.Species,
                OwnerID     = new Guid(User.Identity.GetUserId())
            };

            petService.Create(dbPet);

            return(Ok());
        }
Esempio n. 23
0
        public void StartUI()
        {
            string[] menuItems =
            {
                "List All Pets",
                "Create Pet",
                "Delete Pet",
                "Update Pet",
                "Search by type",
                "Sort Pets by price",
                "List 5 cheapest pets",
                "Exit"
            };

            int selection = ShowMenu(menuItems);

            while (selection != 8)
            {
                while (selection != 8)
                {
                    switch (selection)
                    {
                    case 1:
                        List <Pet> pets = _petService.GetPets();
                        ListPets(pets);
                        Console.WriteLine();
                        break;

                    case 2:
                        var pet = MakeNewPet();
                        _petService.Create(pet);
                        Console.WriteLine();
                        break;

                    case 3:
                        DeletePet();
                        break;

                    case 4:
                        UpdatePet();
                        Console.WriteLine();
                        break;

                    case 5:
                        SearchPetByType();
                        Console.WriteLine();
                        break;

                    case 6:
                        GetSortedPetsByPrice();
                        Console.WriteLine();
                        break;

                    case 7:
                        ListCheapestPets();
                        Console.WriteLine();
                        break;

                    default:
                        break;
                    }
                    selection = ShowMenu(menuItems);
                }
                Console.WriteLine("Bye bye!");
                Console.ReadLine();
            }
        }
Esempio n. 24
0
        public IActionResult Create(Petvm item)
        {
            var id = _service.Create(item);

            return(CreatedAtRoute("GetPet", new { id = item.Id }, item));
        }
Esempio n. 25
0
        public ActionResult PetCreate([FromForm] PetCO request)
        {
            var sonuc = new ResultDTO();

            if (request == null)
            {
                throw new PetClinicAppointmentBadRequestException("You have not sent any data!");
            }

            if (string.IsNullOrEmpty(request.Name))
            {
                throw new PetClinicAppointmentBadRequestException("Pet name cannot be empty!");
            }

            if (string.IsNullOrEmpty(request.PlaceOfBirth))
            {
                throw new PetClinicAppointmentBadRequestException("Pet place of birth cannot be empty!");
            }

            if (string.IsNullOrEmpty(request.Birthdate.ToLongDateString()))
            {
                throw new PetClinicAppointmentBadRequestException("Pet birthdate cannot be empty!");
            }

            if (request.UserGuid == null)
            {
                throw new PetClinicAppointmentBadRequestException("User guid cannot be empty!");
            }

            var user = _userService.GetByGuid(request.UserGuid);

            if (user == null)
            {
                throw new PetClinicAppointmentNotFoundException("User not found!");
            }

            var picturePath = Path.Combine("Assets", "defaultPet.jpeg");

            var dto = new PetDTO()
            {
                Guid        = Guid.NewGuid(),
                Deleted     = false,
                Actived     = true,
                CreatedDate = DateTime.Now,
                DogumTarihi = request.Birthdate,
                DogumYeri   = request.PlaceOfBirth,
                Name        = request.Name,
                User        = null,
                UserId      = user.Id,
                Resim       = picturePath
            };

            var durum = _petService.Create(dto);

            if (durum > 0)
            {
                sonuc.Status = EDurum.SUCCESS;
                sonuc.Message.Add(new MessageDTO()
                {
                    Code        = HttpStatusCode.OK,
                    Status      = EDurum.SUCCESS,
                    Description = "Pet was created successfully."
                });
                sonuc.Data = new { pet = new { dto.Guid } };
            }
            else
            {
                throw new PetClinicAppointmentBadRequestException("Error adding pet!");
            }

            return(Ok(sonuc));
        }
Esempio n. 26
0
 public void SavePet(Pet pet)
 {
     petService.Create(pet);
 }
Esempio n. 27
0
        public void StartUI()
        {
            string[] menuItems =
            {
                "List All Pets",
                "Search By Type of Pet",
                "Breed A new Pet(Create)",
                "Release pet(Delete)",
                "Groom Pet(Update)",
                "Sort Pets by Price",
                "Get 5 cheapest pets",
                "Exit"
            };

            var selection = ShowMenu(menuItems);

            while (selection != 8)
            {
                switch (selection)
                {
                case 1:
                    ListPets();
                    break;

                case 2:
                    Console.WriteLine("Input Number of Pet Type (1-5): ");
                    SearchByPetType();
                    break;

                case 3:
                    object pet = CreatePet();
                    _petService.Create((Pet)pet);
                    break;

                case 4:
                    DeletePet();
                    break;

                case 5:
                    idOfPet = GetPetId();
                    var petForUpdate = _petService.FindPetById(idOfPet);
                    Console.WriteLine("Grooming" + petForUpdate.Name);
                    var newPetName  = NewPetData("New Name for " + petForUpdate.Id);
                    var newPetType  = NewPetData("New Type for " + petForUpdate.Id);
                    var newPetOwner = NewPetData("New Owner for " + petForUpdate.Id);

                    petForUpdate.Name = newPetName;
                    //petForUpdate.Type = newPetType;
                    Pet.Type2 thePetType;
                    int       typePet;
                    if (int.TryParse(newPetType, out typePet) && typePet <= 5)
                    {
                        switch (typePet)
                        {
                        case 1:
                            thePetType = Pet.Type2.Dog;
                            break;

                        case 2:
                            thePetType = Pet.Type2.Cat;
                            break;

                        case 3:
                            thePetType = Pet.Type2.Hawk;
                            break;

                        case 4:
                            thePetType = Pet.Type2.Lion;
                            break;

                        default:
                            thePetType = Pet.Type2.Snake;
                            break;
                        }
                    }
                    else
                    {
                        throw new InvalidDataException(message: "Error, you did not chose type of pet correctly. MOron.");
                    }
                    petForUpdate.Type          = thePetType;
                    petForUpdate.previousOwner = newPetOwner;

                    _petService.Update(petForUpdate);
                    break;

                case 6:
                    sortPetsByPrice();
                    break;

                case 7:
                    showCheapestPets();
                    break;

                case 8:
                    break;
                }
                selection = ShowMenu(menuItems);
            }
            Console.WriteLine("Later, pal. And remember, there is no refund policy!");
            Console.ReadLine();
        }
Esempio n. 28
0
        public void InitData()
        {
            Pet pet1 = new Pet
            {
                Name      = "Kitty",
                Type      = "Cat",
                Color     = "Black",
                Birthday  = new DateTime(2019, 6, 2),
                SoldDate  = new DateTime(2020, 3, 1),
                PrevOwner = "Gustaf Edinson",
                Price     = 800.25,
            };

            _petService.Create(pet1);

            Pet pet2 = new Pet
            {
                Name      = "Barkley",
                Type      = "Dog",
                Color     = "Grey",
                Birthday  = new DateTime(2018, 2, 2),
                SoldDate  = new DateTime(2020, 1, 6),
                PrevOwner = "Alfonso Davies",
                Price     = 650.60,
            };

            _petService.Create(pet2);

            Pet pet3 = new Pet
            {
                Name      = "Jerry",
                Type      = "Mouse",
                Color     = "Red",
                Birthday  = new DateTime(2020, 6, 7),
                SoldDate  = new DateTime(2020, 2, 7),
                PrevOwner = "Save Pets Company",
                Price     = 30,
            };

            _petService.Create(pet3);

            Pet pet4 = new Pet
            {
                Name      = "Abraham",
                Type      = "Pig",
                Color     = "Pink",
                Birthday  = new DateTime(2020, 2, 7),
                SoldDate  = new DateTime(2020, 3, 7),
                PrevOwner = "Farmer Bob",
                Price     = 320.60,
            };

            _petService.Create(pet4);

            Pet pet5 = new Pet
            {
                Name      = "Stefani",
                Type      = "Cat",
                Color     = "Purple",
                Birthday  = new DateTime(2019, 6, 5),
                SoldDate  = new DateTime(2020, 2, 5),
                PrevOwner = "Sir Alex",
                Price     = 10500,
            };

            _petService.Create(pet5);

            Pet pet6 = new Pet
            {
                Name      = "Van Gogh",
                Type      = "Dog",
                Color     = "White",
                Birthday  = new DateTime(2020, 2, 7),
                SoldDate  = new DateTime(2020, 5, 7),
                PrevOwner = "Oscar Wild",
                Price     = 16499.99,
            };

            _petService.Create(pet6);
        }
Esempio n. 29
0
        public void StartUI()
        {
            string[] menuItems =
            {
                "List All Pets",
                "Search by type",
                "Create Pet",
                "Delete Pet",
                "Update Pet",
                "Sort Pets by price",
                "List 5 cheapest pets",
                "Exit"
            };
            var selection = ShowMenu(menuItems);

            while (selection != 9)
            {
                switch (selection)
                {
                case 1:
                    ListAllPets();
                    Console.WriteLine();
                    break;

                case 2:
                    SearchPetByType();
                    Console.WriteLine();
                    break;

                case 3:
                    var pet = BuildNewPet();
                    _petService.Create(pet);
                    Console.WriteLine();
                    break;

                case 4:
                    DeletePet();
                    Console.WriteLine();
                    break;

                case 5:
                    UpdatePet();
                    Console.WriteLine();
                    break;

                case 6:
                    GetPetsSortedByPrice();
                    Console.WriteLine();
                    break;

                case 7:
                    List5CheapestPets();
                    Console.WriteLine();
                    break;
                }
                selection = ShowMenu(menuItems);
            }

            Console.WriteLine("Bye bye!");
            Console.Write("$ ");
            Console.ReadLine();
        }
Esempio n. 30
0
        public void InitData()
        {
            Pet pet1 = new Pet
            {
                Name          = "Dante",
                Type          = Pet.Type2.Dog,
                Birthdate     = new DateTime(2013, 7, 8),
                SoldDate      = new DateTime(2013, 7, 8),
                previousOwner = "Uriel Sorensson",
                Price         = 250
            };

            _petService.Create(pet1);
            Pet pet2 = new Pet
            {
                Name      = "Vergil",
                Type      = Pet.Type2.Cat,
                Birthdate = new DateTime(2013, 7, 8),
                SoldDate  = new DateTime(2013, 7, 8),
                //Color = "Blue",
                previousOwner = "Bruce Wayne",
                Price         = 550
            };

            _petService.Create(pet2);
            Pet pet3 = new Pet
            {
                Name      = "Lady",
                Type      = Pet.Type2.Hawk,
                Birthdate = new DateTime(2013, 7, 8),
                SoldDate  = new DateTime(2013, 7, 8),
                //Color = "Brown",
                previousOwner = "Loki Odinson",
                Price         = 360
            };

            _petService.Create(pet3);
            Pet pet4 = new Pet
            {
                Name      = "Trish",
                Type      = Pet.Type2.Lion,
                Birthdate = new DateTime(2012, 6, 4),
                SoldDate  = new DateTime(2012, 6, 4),
                //Color = "White",
                previousOwner = "Urizen Sparkles",
                Price         = 70
            };

            _petService.Create(pet4);
            Pet pet5 = new Pet
            {
                Name      = "Iris",
                Type      = Pet.Type2.Snake,
                Birthdate = new DateTime(2012, 6, 4),
                SoldDate  = new DateTime(2012, 6, 4),
                //Color = "Orange",
                previousOwner = "Simba",
                Price         = 120
            };

            _petService.Create(pet5);
        }