Ejemplo n.º 1
0
 public ActionResult <PetType> Post([FromBody] PetType newPetType)
 {
     try
     {
         return(StatusCode(201, _petTypeService.Createtype(newPetType)));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
 public ActionResult <PetType> Put(int id, [FromBody] PetType petType)
 {
     try
     {
         return(StatusCode(202, _petTypeService.UploadPetTypeByID(id, petType)));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
Ejemplo n.º 3
0
 public PetType EditPetType(int idOfPetTypeToEdit, PetType editedPetType)
 {
     if (!_petTypeRepository.GetAllPetTypes().Exists(x => x.ID == idOfPetTypeToEdit))
     {
         throw new KeyNotFoundException("A pet with this ID does not exist");
     }
     else
     {
         return(_petTypeRepository.EditPetType(idOfPetTypeToEdit, editedPetType));
     }
 }
Ejemplo n.º 4
0
 public PetType Update(int index, PetType petType)
 {
     try
     {
         return(_ptrep.Update(index, petType));
     }
     catch (Exception e)
     {
         throw new ServiceException("Error updating pet type: " + e.Message, e);
     }
 }
Ejemplo n.º 5
0
 public PetDTO(int id, string name, PetType petType, DateTime birthDate, DateTime soldDate, string color, Owner previousOwner, double price)
 {
     ID            = id;
     Name          = name;
     PetType       = petType;
     BirthDate     = birthDate;
     SoldDate      = soldDate;
     Color         = color;
     PreviousOwner = previousOwner;
     Price         = price;
 }
Ejemplo n.º 6
0
 public PetType Add(PetType petType)
 {
     try
     {
         return(_ptrep.Add(petType));
     }
     catch (Exception e)
     {
         throw new ServiceException("Error adding pet type: " + e.Message, e);
     }
 }
Ejemplo n.º 7
0
        public ActionResult Update(PetType petType)
        {
            if (ModelState.IsValid)
            {
                db.Entry(petType).State = EntityState.Modified;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(petType));
        }
        public ActionResult Create(PetType petType)
        {
            if (ModelState.IsValid)
            {
                db.PetTypes.Add(petType);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(petType));
        }
Ejemplo n.º 9
0
        public PetType Update(PetType petTypeUpdate)
        {
            var petTypeFromDB = ReadById(petTypeUpdate.Id);

            if (petTypeFromDB != null)
            {
                petTypeFromDB.Type = petTypeUpdate.Type;
                return(petTypeFromDB);
            }
            return(null);
        }
Ejemplo n.º 10
0
        private async ValueTask <bool> HandleSetPet(ClientPlayer sender, PetType pet)
        {
            if (_game.GameState == GameStates.Started && await sender.Client.ReportCheatAsync(RpcCalls.SetPet, "Client tried to change pet while not in lobby"))
            {
                return(false);
            }

            PlayerInfo.Pet = pet;

            return(true);
        }
        public PetType UpdatePetType(PetType type)
        {
            PetType petType = ((List <PetType>)PetTypes).Find((x) => { return(x.ID == type.ID); });

            if (petType != null)
            {
                petType.Name = type.Name;
                return(petType);
            }
            return(null);
        }
        public PetType DeletePetType(int ID)
        {
            PetType petType = PetTypes.Where((x) => { return(x.ID == ID); }).FirstOrDefault();

            if (petType != null)
            {
                ((List <PetType>)PetTypes).Remove(petType);
                return(petType);
            }
            return(null);
        }
Ejemplo n.º 13
0
 private void AddPet(string name, Owner owner, PetType petType, string race)
 {
     _dataContext.Pets.Add(new Pet
     {
         Born    = DateTime.Now.AddYears(-2),
         Name    = name,
         Owner   = owner,
         PetType = petType,
         Race    = race
     });
 }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("Id,Name")] PetType petType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(petType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(petType));
        }
Ejemplo n.º 15
0
        public ActionResult Create([Bind(Include = "PetTypeID,PetTypeName")] PetType petType)
        {
            if (ModelState.IsValid)
            {
                db.PetType.Add(petType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(petType));
        }
Ejemplo n.º 16
0
 public ActionResult <PetType> Put(int id, [FromBody] PetType pettype)
 {
     try
     {
         return(Accepted(petTypeService.updatePet(id, pettype)));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
Ejemplo n.º 17
0
 public PetType UploadPetTypeByID(int id, PetType petType)
 {
     if (id < 0)
     {
         throw new Exception("Please, enter a valid value for the ID");
     }
     else if (petType == null)
     {
         throw new Exception("Please, include the new Pet Type");
     }
     return(_petTypeRepo.UploadPetTypeByID(id, petType));
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Get pets for owners of a particular gender
        /// </summary>
        /// <param name="gender">Pet Owner gender</param>
        /// <param name="petType">Type of Owner pet</param>
        /// <returns></returns>
        public List <Pet> GetPetsByOwnerGenderAndPetType(Gender gender, PetType petType)
        {
            var genderStr  = gender.ToString();
            var petTypeStr = petType.ToString();

            return(PeopleList
                   .Where(person => person.Gender.ToString() == genderStr && person.Pets?.Count > 0)
                   .SelectMany(person => person.Pets)
                   .Where(pet => pet.Type.ToString() == petTypeStr)
                   .OrderBy(pet => pet.Name)
                   .ToList());
        }
Ejemplo n.º 19
0
 public static IPet CreatePet(PetType type)
 {
     switch (type)
     {
         case PetType.Cat:
             return new Cat();
         case PetType.Dog:
             return new Dog();
         default:
             return null;
     }
 }
Ejemplo n.º 20
0
        public bool UpdatePetType(PetType type)
        {
            var ListIndex = petTypes.FindIndex(x => x.Id == type.Id);

            if (ListIndex == -1)
            {
                throw new KeyNotFoundException($"pet type with id {type.Id} doesnt exist");
            }

            petTypes[ListIndex] = type;
            return(true);
        }
Ejemplo n.º 21
0
 public List <Pet> SearchByType(PetType petType)
 {
     try
     {
         List <Pet> result = _prep.GetAll().Where(pet => pet.Type.Equals(petType)).ToList();
         return(result);
     }
     catch (Exception e)
     {
         throw new ServiceException("Error getting pet by type: " + e.Message, e);
     }
 }
Ejemplo n.º 22
0
        // Remove later for UOW
        public PetType UpdatePetType(PetType petTypeUpdate)
        {
            var petTypeFromDB = this.ReadById(petTypeUpdate.petTypeId);

            if (petTypeFromDB != null)
            {
                petTypeFromDB.name = petTypeUpdate.name;

                return(petTypeFromDB);
            }
            return(null);
        }
Ejemplo n.º 23
0
 public PetType CreatePetType(PetType petType)
 {
     if (petType.Pet == null || petType.Pet.Id <= 0)
     {
         throw new InvalidDataException("To create pet type you need a pet");
     }
     if (_petRepo.ReadById(petType.Pet.Id) == null)
     {
         throw new InvalidDataException("Pet type not found");
     }
     return(_petTypeRepo.Create(petType));
 }
 public ActionResult <PetType> Post([FromBody] PetType value)
 {
     try
     {
         return(string.IsNullOrEmpty(value.name) ? BadRequest("Name is required to create a petType") : StatusCode(201, _petTypeService.CreatePetType(value)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(StatusCode(500, e));
     }
 }
Ejemplo n.º 25
0
        public PetType DeletePetType(Guid typeID)
        {
            PetType dbEntry = context.PetTypes
                              .FirstOrDefault(p => p.TypeID == typeID);

            if (dbEntry != null)
            {
                context.PetTypes.Remove(dbEntry);
                context.SaveChanges();
            }
            return(dbEntry);
        }
        public void Add(PetType petType)
        {
            var sql = @"INSERT INTO [PetType] ([Type],[isActive])
                       OUTPUT inserted.Id
                       VALUES(@Type, @isActive)";

            using var db = new SqlConnection(ConnectionString);

            var id = db.ExecuteScalar <int>(sql, petType);

            petType.Id = id;
        }
Ejemplo n.º 27
0
 public ActionResult <PetType> Post([FromBody] PetType petType)
 {
     try
     {
         _petTypeService.AddNewPetType(petType);
         return(petType);
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
Ejemplo n.º 28
0
        public async Task <IActionResult> PostPetType([FromBody] PetType petType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.PetTypes.Add(petType);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPetType", new { id = petType.Id }, petType));
        }
Ejemplo n.º 29
0
 private void AddPet(string name, Customer owner, PetType petType, string race)
 {
     _context.Pets.Add(new Pet
     {
         Born     = DateTime.Now.AddYears(-2),
         Name     = name,
         Customer = owner,
         PetType  = petType,
         Race     = race,
         Remarks  = "Welcome to YourVet!!"
     });
 }
Ejemplo n.º 30
0
 public BasePet GetPet(PetType _type)
 {
     if (_type == PetType.BlueBaBaType)
     {
         return(this.blueBaBa);
     }
     if (_type == PetType.RedBaBaType)
     {
         return(this.redBaBa);
     }
     return(null);
 }
Ejemplo n.º 31
0
 public PetType AddPetType(PetType type)
 {
     if (type != null)
     {
         if ((from x in GetAllPetTypes() where x.Name.ToLower().Equals(type.Name.ToLower()) select x).Count() > 0)
         {
             throw new ArgumentException("Pet type with that name already exists");
         }
         return(PetTypeRepository.AddPetType(type));
     }
     return(null);
 }
Ejemplo n.º 32
0
        private int PetNumberProvider(PetType pet)
        {
            int retPet = 0;
            switch (pet)
            {
                case PetType.worm:
                    {
                        retPet = 7;
                    }
                    break;

                //выпустить синего духа
                case PetType.wormBlueSoul:
                    {
                        retPet = 16;
                    }
                    break;

                //выпустить кита
                case PetType.whale:
                    {
                        retPet = 21;
                    }
                    break;

                //выпустить попоугая
                case PetType.parot:
                    {
                        retPet = 23;
                    }
                    break;
                default: break;
            }
            return retPet;
        }
Ejemplo n.º 33
0
 /// <summary>
 /// There are no comments for DogPetType in the schema.
 /// </summary>
 public void AddToDogPetType(PetType petType)
 {
     base.AddObject("DogPetType", petType);
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Create a new PetType object.
 /// </summary>
 /// <param name="petTypeId">Initial value of PetTypeId.</param>
 public static PetType CreatePetType(int petTypeId)
 {
     PetType petType = new PetType();
     petType.PetTypeId = petTypeId;
     return petType;
 }
Ejemplo n.º 35
0
 /// <summary>
 /// There are no comments for CatPetType in the schema.
 /// </summary>
 public void AddToCatPetType(PetType petType)
 {
     base.AddObject("CatPetType", petType);
 }
Ejemplo n.º 36
0
 public Druid(PetType type)
 {
     pet = new druidPet(type);
 }
Ejemplo n.º 37
0
 public Pet(string name,string age,PetType type)
 {
     Name = name;
     Age = age;
     PetType = type;
 }
Ejemplo n.º 38
0
 public rangerPet(PetType type, PetSize size)
 {
     petType = type;
     petSize = size;
 }
Ejemplo n.º 39
0
 public wizardFamilar(PetType type)
 {
     petType = type;
 }
Ejemplo n.º 40
0
 public druidPet(PetType type)
 {
     petType = type;
 }
Ejemplo n.º 41
0
        private void GetPet(PetType pet = PetType.currentPet)
        {
            try
            {
                //если есть линка посадить в клетку, то проверяем на правильность зверя
                if (driver.FindElement(By.XPath("//a[@title='Посадить в клетку']")).Displayed == true)
                {
                    //если зверь не дефолтный, то сверяем текущего зверя с нужным
                    if (PetNumberProvider(pet) != 0)
                    {
                        string css = string.Format(".pet{0}", PetNumberProvider(pet));
                        //Если нет иконки нужного зверя попадаем в кетч и садим невалидного зверя в клетку,а нужного достаем
                        try
                        {
                            IWebElement temp = driver.FindElement(By.CssSelector(css));
                        }
                        catch
                        {
                            SetPet();

                            //Деревня
                            driver.FindElement(By.Id("m3")).FindElement(By.XPath(".//b")).Click();
                            Delays();
                            //Жилище
                            driver.FindElement(By.LinkText("Жилище")).Click();
                            Delays();
                            //клетка
                            driver.FindElement(By.LinkText("Клетка")).Click();
                            Delays();
                            //вытащить с клетки
                            if (PetNumberProvider(pet) == 0)
                            {
                                driver.FindElement(By.XPath("//input[@value='ВЫПУСТИТЬ ИЗ КЛЕТКИ']")).Click();
                            }
                            else
                            {
                                try
                                {
                                    string xPath = string.Format("//img[contains(@src,'Pet_{0}')]/ancestor::div[contains(@class,'round_block_round_border')]//input[contains(@value,'ВЫПУСТИТЬ')]", PetNumberProvider(pet));
                                    driver.FindElement(By.XPath(xPath)).Click();
                                    Delays();
                                }
                                catch
                                {
                                    string xPath = string.Format("//img[contains(@src,'Pet_{0}s')]/..//input[@value='ВЗЯТЬ В БОЙ']", PetNumberProvider(pet));
                                    driver.FindElement(By.XPath(xPath)).Click();
                                    Delays();
                                };
                            }
                        }
                    }
                }
            }
            //проверка есть ли зверь
            catch
            {
                //Деревня
                driver.FindElement(By.Id("m3")).FindElement(By.XPath(".//b")).Click();
                Delays();
                //Жилище
                driver.FindElement(By.LinkText("Жилище")).Click();
                Delays();
                //клетка
                driver.FindElement(By.LinkText("Клетка")).Click();
                Delays();
                //вытащить с клетки
                if (PetNumberProvider(pet) == 0)
                {
                    driver.FindElement(By.XPath("//input[@value='ВЫПУСТИТЬ ИЗ КЛЕТКИ']")).Click();
                }
                else
                {
                    try
                    {
                        string xPath = string.Format("//img[contains(@src,'Pet_{0}')]/ancestor::div[contains(@class,'round_block_round_border')]//input[contains(@value,'ВЫПУСТИТЬ')]", PetNumberProvider(pet));
                        driver.FindElement(By.XPath(xPath)).Click();
                        Delays();
                    }
                    catch
                    {
                        string xPath = string.Format("//img[contains(@src,'Pet_{0}s')]/..//input[@value='ВЗЯТЬ В БОЙ']", PetNumberProvider(pet));
                        driver.FindElement(By.XPath(xPath)).Click();
                        Delays();
                    };
                }
            }
        }