Example #1
0
        public Animal CreateMarine(MarineSpecies marineSpecies)
        {
            Marine animalObj = null;

            switch (marineSpecies)
            {
            case MarineSpecies.Goldfish:
                animalObj = new Goldfish();
                break;

            case MarineSpecies.Whales:
                animalObj = new Whales();
                break;


            default:
                Debug.Assert(false, "To be completed!");
                break;
            }


            animalObj.CategoryType = CategoryType.Marine;

            return(animalObj);     //return the created animal object.
        }
        public static Marines CreateMarine(MarineSpecies Species)
        {
            Marines animalObj = null; //type not known at this time

            //type determined by late binding
            switch (Species)
            {
                case MarineSpecies.Dolphine:
                    animalObj = new Dolphine();           //Late binding
                    break;
                //Continue with the rest
                case MarineSpecies.Shark:
                    animalObj = new Shark();    //Late binding
                    break;

                default:
                    Debug.Assert(false, "To be completed!");
                    break;
            }

            //set the category
            animalObj.Category = CategoryType.Marine;

            return animalObj; //return the crated animal Object
        }
Example #3
0
        public static Marine CreateMarine(MarineSpecies species)
        {
            //type not known at this time
            Marine animalObj = null;

            try
            {
                //type determined by late binding
                switch (species)
                {
                case MarineSpecies.Shark:

                    animalObj = new Shark();     //late binding

                    if (animalObj == null)
                    {
                        NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException();

                        throw (ex);
                    }

                    break;


                case MarineSpecies.Turtle:

                    animalObj = new Turtle();     //late binding

                    if (animalObj == null)
                    {
                        NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException();

                        throw (ex);
                    }

                    break;

                default:

                    Debug.Assert(false, "to be completed");

                    break;
                }
            }

            //custom exception
            catch (Exception e)
            {
                e.Message.ToString();
                NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException();

                throw (ex);
            }
            finally
            {
                //set the category
                animalObj.Category = CategoryType.Marine;
            }
            return(animalObj);
        }
Example #4
0
        public static MarineAnimal CreateMarine(MarineSpecies Species)
        {
            MarineAnimal animalObj = null;//Marine animal type not know yet.

            //Lets determine users choice of animal.
            switch (Species)
            {
            case MarineSpecies.Crayfish:
                animalObj = new Crayfish();
                break;

            case MarineSpecies.Salmon:
                animalObj = new Salmon();
                break;

            default:
                Debug.Assert(false, "Not implemented");
                break;
            }

            //Set animal category
            animalObj.Category = CategoryType.Marine;

            return(animalObj);//Return created instance of object marine animal
        }
Example #5
0
        private Animal castAnimal(int speciesIndex, CategoryType type)
        {
            //Checking which object to create:
            if (type == CategoryType.Bird)
            {
                BirdSpecies speciestype = (BirdSpecies)speciesIndex;
                animalis = BirdFactory.CreateBird(speciestype);
            }
            else if (type == CategoryType.Insect)
            {
                InsectSpecies insectSpec = (InsectSpecies)speciesIndex;
                animalis = InsectFactory.CreateInsect(insectSpec);
            }
            else if (type == CategoryType.Mammal)
            {
                MammalSpecies mammalSpec = (MammalSpecies)speciesIndex;
                animalis = MammalFactory.CreateMammal(mammalSpec);
            }
            else if (type == CategoryType.Marine)
            {
                MarineSpecies marineSpec = (MarineSpecies)speciesIndex;
                animalis = MarineFactory.CreateMarine(marineSpec);
            }
            else if (type == CategoryType.Reptile)
            {
                ReptileSpecies reptileSpec = (ReptileSpecies)speciesIndex;
                animalis = ReptileFactory.CreateReptile(reptileSpec);
            }

            return(animalis);
        }
        public async Task <IActionResult> PutMarineSpecies([FromRoute] int id, [FromBody] MarineSpecies marineSpecies)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != marineSpecies.IdPk)
            {
                return(BadRequest());
            }

            _context.Entry(marineSpecies).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MarineSpeciesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostMarineSpecies([FromBody] MarineSpecies marineSpecies)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.MarineSpecies.Add(marineSpecies);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetMarineSpecies", new { id = marineSpecies.IdPk }, marineSpecies));
        }
Example #8
0
        public static MarineAnimal CreateMarine(MarineSpecies Species)
        {
            MarineAnimal animalObj = null;//Marine animal type not know yet.

            //Lets determine users choice of animal.
            switch (Species)
            {
                case MarineSpecies.Crayfish:
                    animalObj = new Crayfish();
                    break;
                case MarineSpecies.Salmon:
                    animalObj = new Salmon();
                    break;

                default:
                    Debug.Assert(false, "Not implemented");
                    break;
            }

            //Set animal category
            animalObj.Category = CategoryType.Marine;

            return animalObj;//Return created instance of object marine animal
        }
        public static Marine CreateMarine(MarineSpecies species)
        {
            //type not known at this time
            Marine animalObj = null;

            try
            {
                //type determined by late binding
                switch (species)
                {

                    case MarineSpecies.Shark:

                        animalObj = new Shark(); //late binding

                        if (animalObj == null)
                        {
                            NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException();

                            throw (ex);
                        }

                        break;

                    case MarineSpecies.Turtle:

                        animalObj = new Turtle(); //late binding

                        if (animalObj == null)
                        {
                            NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException();

                            throw (ex);
                        }

                        break;

                    default:

                        Debug.Assert(false, "to be completed");

                        break;

                }
            }

            //custom exception
            catch (Exception e)
            {
                e.Message.ToString();
                NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException();

                throw (ex);
            }
            finally
            {

                //set the category
                animalObj.Category = CategoryType.Marine;

            }
            return animalObj;
        }
        private Animal SetAnimalType()
        {
            Animal newAnimal        = new Animal();
            var    selectedCategori = listBxCategori.SelectedIndex;

            if (string.IsNullOrEmpty(listbxAnimalSpecies.Text))
            {
                showValidationMessage.ShowNewMessageBox("Du måste välja djurarten från listan!");
                return(newAnimal = null);
            }
            else
            {
                switch (selectedCategori)
                {
                case 0:
                    BirdSpecies birdSpecies = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), listbxAnimalSpecies.Text);
                    BirdFactory birdFactory = new BirdFactory();
                    newAnimal = birdFactory.Createbird(birdSpecies);
                    break;

                case 1:
                    InsectSpecies insectSpecies = (InsectSpecies)Enum.Parse(typeof(InsectSpecies), listbxAnimalSpecies.Text);
                    InsectFactory insectFactory = new InsectFactory();
                    newAnimal = insectFactory.CreateInsect(insectSpecies);
                    break;

                case 2:
                    MammalSpecies mammalSpecies = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listbxAnimalSpecies.Text);
                    MammalFactory mammalFactory = new MammalFactory();
                    int           daysOfQuarantine;
                    int           numberOfteeth;
                    bool          underQuarantine = chBoxUnderQuarantine.Checked;
                    if (!helper.CheckInteger(texBoxDaysInQuarantine.Text, out daysOfQuarantine) && underQuarantine == true)
                    {
                        string messageDayOfQuarantine = "You have entered the error value in days of quarantine";
                        errorDayInQuarantiner.SetError(texBoxDaysInQuarantine, messageDayOfQuarantine);
                        showValidationMessage.ShowNewMessageBox(messageDayOfQuarantine);
                        newAnimal = null;
                        break;
                    }
                    else
                    {
                        errorDayInQuarantiner.Clear();
                    }
                    if (!int.TryParse(tboxNoOfTeeth.Text, out numberOfteeth))
                    {
                        errorNoOfTeeth.SetError(tboxNoOfTeeth, "You have entered the error value");
                        showValidationMessage.TeethException(tboxNoOfTeeth.Text);
                        newAnimal = null;
                        break;
                    }
                    else
                    {
                        errorNoOfTeeth.Clear();
                    }


                    newAnimal = mammalFactory.CreateMammal(mammalSpecies, daysOfQuarantine, underQuarantine, numberOfteeth);

                    break;

                case 3:
                    MarineSpecies marineSpecies = (MarineSpecies)Enum.Parse(typeof(MarineSpecies), listbxAnimalSpecies.Text);
                    MarineFactory marineFactory = new MarineFactory();
                    newAnimal = marineFactory.CreateMarine(marineSpecies);
                    break;

                case 4:
                    ReptileSpecies reptileSpecies = (ReptileSpecies)Enum.Parse(typeof(ReptileSpecies), listbxAnimalSpecies.Text);
                    ReptileFactory reptileFactory = new ReptileFactory();
                    newAnimal = reptileFactory.CreateReptile(reptileSpecies);
                    break;
                }
            }

            return(newAnimal);
        }