예제 #1
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            //Posible exception

            IAquarium aquarium = this.aquariums.First(a => a.Name == aquariumName);

            IFish fish = null;

            switch (fishType)
            {
            case "FreshwaterFish":
                fish = new FreshwaterFish(fishName, fishSpecies, price);
                aquarium.AddFish(fish);

                return(aquarium.GetType().Name == "FreshwaterAquarium"
                        ? string.Format(OutputMessages.FishAdded, fishType, aquariumName)
                        : OutputMessages.UnsuitableWater);

            case "SaltwaterFish":
                fish = new SaltwaterFish(fishName, fishSpecies, price);
                aquarium.AddFish(fish);

                return(aquarium.GetType().Name == "SaltwaterAquarium"
                        ? string.Format(OutputMessages.FishAdded, fishType, aquariumName)
                        : OutputMessages.UnsuitableWater);

            default:
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }
        }
예제 #2
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            if (fishType != nameof(SaltwaterFish) && fishType != nameof(FreshwaterFish))
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            IAquarium aquarium = this.aquaria.First(x => x.Name == aquariumName);

            if (aquarium.GetType().Name == nameof(SaltwaterAquarium) && fishType == nameof(FreshwaterFish) || aquarium.GetType().Name == nameof(FreshwaterAquarium) && fishType == nameof(SaltwaterFish))
            {
                return(string.Format(OutputMessages.UnsuitableWater));
            }

            if (fishType == nameof(FreshwaterFish))
            {
                aquarium.AddFish(new FreshwaterFish(fishName, fishSpecies, price));
            }
            else
            {
                aquarium.AddFish(new SaltwaterFish(fishName, fishSpecies, price));
            }

            return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
        }
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            if (fishType != "FreshwaterFish" && fishType != "SaltwaterFish")
            {
                throw new InvalidOperationException("Invalid fish type.");
            }
            IFish fish = null;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            IAquarium aquarium = this.aquariums.Where(x => x.Name == aquariumName).FirstOrDefault();

            if (aquarium.GetType().Name.Contains("Fresh") && fish.GetType().Name.Contains("Fresh"))
            {
                aquarium.AddFish(fish);
            }
            else if (aquarium.GetType().Name.Contains("Salt") && fish.GetType().Name.Contains("Salt"))
            {
                aquarium.AddFish(fish);
            }
            else
            {
                return($"Water not suitable.");
            }

            return($"Successfully added {fish.GetType().Name} to {aquariumName}.");
        }
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IAquarium aquarium = aquariums.FirstOrDefault(p => p.Name == aquariumName);

            IFish fish = null;

            if (fishType == nameof(FreshwaterFish))
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);

                if (aquarium.GetType().Name == nameof(FreshwaterAquarium))
                {
                    aquarium.AddFish(fish);
                    return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
                }
            }
            else if (fishType == nameof(SaltwaterFish))
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);

                if (aquarium.GetType().Name == nameof(SaltwaterAquarium))
                {
                    aquarium.AddFish(fish);
                    return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
                }
            }
            else
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidFishType));
            }
            return(string.Format(OutputMessages.UnsuitableWater));
        }
예제 #5
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IAquarium aqurium = aquariums.First(a => a.Name == aquariumName);

            if (fishType == "FreshwaterFish")
            {
                if (aqurium.GetType().Name != "FreshwaterAquarium")
                {
                    throw new InvalidOperationException(OutputMessages.UnsuitableWater);
                }
                aqurium.AddFish(new FreshwaterFish(fishName, fishSpecies, price));
            }
            else if (fishType == "SaltwaterFish")
            {
                if (aqurium.GetType().Name != "SaltwaterAquarium")
                {
                    throw new InvalidOperationException(OutputMessages.UnsuitableWater);
                }
                aqurium.AddFish(new SaltwaterFish(fishName, fishSpecies, price));
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            return(String.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
        }
예제 #6
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish     fish     = null;
            IAquarium aquarium = aquariums.FirstOrDefault(x => x.Name == aquariumName);

            if (fishType != nameof(FreshwaterFish) && fishType != nameof(SaltwaterFish))
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }
            else
            {
                string currentAquariumType = aquarium.GetType().Name;

                if (fishType == "FreshwaterFish" && currentAquariumType == "FreshwaterAquarium")
                {
                    fish = new FreshwaterFish(fishName, fishSpecies, price);
                }
                else if (fishType == "SaltwaterFish" && currentAquariumType == "SaltwaterAquarium")
                {
                    fish = new SaltwaterFish(fishName, fishSpecies, price);
                }
                else
                {
                    return(OutputMessages.UnsuitableWater);
                }
                aquarium.AddFish(fish);
                return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
            }
        }
예제 #7
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish = null;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }

            if (fish == null)
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            IAquarium seachedAqua = aquariums.FirstOrDefault(a => a.Name == aquariumName);

            if (seachedAqua.GetType().Name == "SaltwaterAquarium" && fishType == "FreshwaterFish")
            {
                return($"Water not suitable.");
            }
            if (seachedAqua.GetType().Name == "FreshwaterAquarium" && fishType == "SaltwaterFish")
            {
                return($"Water not suitable.");
            }

            seachedAqua.AddFish(fish);
            return($"Successfully added {fishType} to {aquariumName}.");
        }
예제 #8
0
파일: Controller.cs 프로젝트: nadsit/Study
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            if (fishType != "FreshwaterFish" && fishType != "SaltwaterFish")
            {
                throw new InvalidOperationException("Invalid fish type.");
            }

            IAquarium aquarium = aquariums.FirstOrDefault(a => a.Name == aquariumName);

            string aquariumToFish = string.Empty;

            IFish fish = null;

            if (fishType == "FreshwaterFish")
            {
                fish           = new FreshwaterFish(fishName, fishSpecies, price);
                aquariumToFish = "Freshwater";
            }
            else if (fishType == "SaltwaterFish")
            {
                fish           = new SaltwaterFish(fishName, fishSpecies, price);
                aquariumToFish = "Saltwater";
            }

            if (!aquarium.GetType().Name.Contains(aquariumToFish))
            {
                return("Water not suitable.");
            }

            aquarium.AddFish(fish);

            return($"Successfully added {fish.GetType().Name} to {aquarium.Name}.");
        }
예제 #9
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish = null;

            if (fishType != "FreshwaterFish" && fishType != "SaltwaterFish")
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }
            else if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }

            IAquarium aquarium = aquariums.FirstOrDefault(x => x.Name == aquariumName);
            Fish      fish1    = fish as Fish;

            if (fish1.FIshLivingPlace != aquarium.GetType().Name)
            {
                return("Water not suitable.");
            }
            else
            {
                aquarium.AddFish(fish);
                return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
            }
        }
        public string AddFish(string aquariumName,
                              string fishType, string fishName,
                              string fishSpecies, decimal price)
        {
            IFish fish = null;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException
                          (ExceptionMessages.InvalidFishType);
            }

            IAquarium aquarium = GetAquariumByName(aquariumName);

            if (((fish is FreshwaterFish) && (aquarium is FreshwaterAquarium)) ||
                ((fish is SaltwaterFish) && (aquarium is SaltwaterAquarium)))
            {
                aquarium.AddFish(fish);
                return(string.Format(OutputMessages
                                     .EntityAddedToAquarium, fishType, aquariumName));
            }

            return(OutputMessages.UnsuitableWater);
        }
예제 #11
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IAquarium aquarium = aquariums[aquariumName];

            IFish fish = null;

            if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }

            if (fish == null)
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            if ((fishType == "SaltwaterFish" && aquarium.GetType().Name == "SaltwaterAquarium") ||
                (fishType == "FreshwaterFish" && aquarium.GetType().Name == "FreshwaterAquarium"))
            {
                aquarium.AddFish(fish);
                return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
            }
            else
            {
                return(OutputMessages.UnsuitableWater);
            }
        }
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish;

            if (fishType == typeof(FreshwaterFish).Name)
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == typeof(SaltwaterFish).Name)
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            IAquarium aquarium = this.aquariums.FirstOrDefault(a => a.Name == aquariumName);

            string aquariumType        = aquarium.GetType().Name[0].ToString();
            string fishTypeFirstLetter = fishType[0].ToString();

            if (aquariumType != fishTypeFirstLetter)
            {
                return(OutputMessages.UnsuitableWater);
            }
            else
            {
                aquarium.AddFish(fish);
                return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
            }
        }
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            IAquarium currentAquarium = this.aquariums.FirstOrDefault(a => a.Name == aquariumName);

            string aquariumType = currentAquarium.GetType().Name;

            bool isTheRightAquariumForTheRightFish =
                fishType == "FreshwaterFish" && aquariumType == "FreshwaterAquarium" ||
                fishType == "SaltwaterFish" && aquariumType == "SaltwaterAquarium";

            if (isTheRightAquariumForTheRightFish)
            {
                currentAquarium.AddFish(fish);
                return(string.Format(OutputMessages.EntityAddedToAquarium, fish.GetType().Name, currentAquarium.Name));
            }
            else
            {
                return(OutputMessages.UnsuitableWater);
            }
        }
예제 #14
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)//todo
        {
            IAquarium aquarium = this.aquariums.FirstOrDefault(a => a.Name == aquariumName);
            IFish     fish     = null;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException("Invalid fish type.");
            }

            if ((fish.GetType().Name.Contains("Freshwater") && aquarium.GetType().Name.Contains("Freshwater")) ||
                (fish.GetType().Name.Contains("Saltwater") && aquarium.GetType().Name.Contains("Saltwater")))
            {
                aquarium.AddFish(fish);

                return($"Successfully added {fishType} to {aquariumName}.");
            }
            else
            {
                return("Water not suitable.");
            }
        }
예제 #15
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish;

            if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidFishType));
            }

            IAquarium aquarium = this.aquariums.FirstOrDefault(x => x.Name == aquariumName);

            if (aquarium.GetType().Name == "FreshwaterAquarium" && fish.GetType().Name == "SaltwaterFish" ||
                aquarium.GetType().Name == "SaltwaterAquarium" && fish.GetType().Name == "FreshwaterFish")
            {
                return(string.Format(OutputMessages.UnsuitableWater));
            }
            else
            {
                aquarium.AddFish(fish);
            }

            return(string.Format(OutputMessages.FishAdded, fishType, aquariumName));
        }
예제 #16
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish = null;

            if (fishType == nameof(FreshwaterFish))
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == nameof(SaltwaterFish))
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException("Invalid fish type.");
            }

            IAquarium aquarium = aquariums.FirstOrDefault(a => a.Name == aquariumName);

            if (fish.GetType().Name.StartsWith("Fresh") && aquarium.GetType().Name.StartsWith("Fresh") ||
                fish.GetType().Name.StartsWith("Salt") && aquarium.GetType().Name.StartsWith("Salt"))
            {
                aquarium.AddFish(fish);
                return($"Successfully added {fishType} to {aquariumName}.");
            }
            else
            {
                return($"Water not suitable.");
            }
        }
예제 #17
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish     fish;
            IAquarium aquarium = CreateAquarium(aquariumName);

            if (fishType == nameof(FreshwaterFish))
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);

                if (aquarium.GetType().Name == nameof(FreshwaterAquarium))
                {
                    aquarium.AddFish(fish);
                }
                else
                {
                    return(ReturnUnsuitableWaterMessage());
                }
            }
            else if (fishType == nameof(SaltwaterFish))
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);

                if (aquarium.GetType().Name == nameof(SaltwaterAquarium))
                {
                    aquarium.AddFish(fish);
                }
                else
                {
                    return(ReturnUnsuitableWaterMessage());
                }
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            string result = string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName);

            return(result);
        }
예제 #18
0
        private void BackgroundImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (aquarium == null)
            {
                InitializeAquarium();
            }
            var fish           = new Fish(100, 180, 0, 20);
            var pos            = e.GetPosition(BackgroundImage);
            var aquariumObject = new AquariumObject(new Point(pos.X, pos.Y),
                                                    new Size(100, 100),
                                                    new Uri("pack://application:,,,/Resources/fish1.png"));

            aquarium.AddFish(fish, aquariumObject);
        }
예제 #19
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IAquarium aquarium = this.aquariums.First(a => a.Name.Equals(aquariumName, StringComparison.OrdinalIgnoreCase));

            IFish fish;

            switch (fishType)
            {
            case nameof(SaltwaterFish):
                fish = new SaltwaterFish(fishName, fishSpecies, price);
                break;

            case nameof(FreshwaterFish):
                fish = new FreshwaterFish(fishName, fishSpecies, price);
                break;

            default:
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            if (fish.GetType().Name == nameof(SaltwaterFish) &&
                aquarium.GetType().Name == nameof(SaltwaterAquarium))
            {
                aquarium.AddFish(fish);
            }
            else if (fish.GetType().Name == nameof(FreshwaterFish) &&
                     aquarium.GetType().Name == nameof(FreshwaterAquarium))
            {
                aquarium.AddFish(fish);
            }
            else
            {
                return(OutputMessages.UnsuitableWater);
            }

            return(String.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
        }
예제 #20
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish     currentFish     = default;
            IAquarium currentAquarium = aquariums.FirstOrDefault(x => x.Name == aquariumName);

            if (fishType == "FreshwaterFish")
            {
                currentFish = new FreshwaterFish(fishName, fishSpecies, price);
                if (currentAquarium.GetType().Name == "FreshwaterAquarium")
                {
                    currentAquarium.AddFish(currentFish);
                    return($"Successfully added {fishType} to {aquariumName}.");
                }
                else
                {
                    return("Water not suitable.");
                }
            }
            else if (fishType == "SaltwaterFish")
            {
                currentFish = new SaltwaterFish(fishName, fishSpecies, price);
                if (currentAquarium.GetType().Name == "SaltwaterAquarium")
                {
                    currentAquarium.AddFish(currentFish);
                    return($"Successfully added {fishType} to {aquariumName}.");
                }
                else
                {
                    return("Water not suitable.");
                }
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }
        }
예제 #21
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            IAquarium aquarium    = aquariums.FirstOrDefault(a => a.Name == aquariumName);
            bool      isFishAdded = false;

            if (fish.GetType().Name == "FreshwaterFish" && aquarium.GetType().Name == "FreshwaterAquarium")
            {
                isFishAdded = true;
            }
            else if (fish.GetType().Name == "SaltwaterFish" && aquarium.GetType().Name == "SaltwaterAquarium")
            {
                isFishAdded = true;
            }

            if (isFishAdded)
            {
                aquarium.AddFish(fish);
            }

            return(isFishAdded ? string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)
                : OutputMessages.UnsuitableWater);

            //if ((fish is FreshwaterFish && aquarium is SaltwaterAquarium)
            //    || (fish is SaltwaterFish && aquarium is FreshwaterAquarium))
            //{
            //    return OutputMessages.UnsuitableWater;
            //}
            //else
            //{
            //    aquarium.AddFish(fish);
            //    return string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName);
            //}
        }
예제 #22
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish;

            if (fishType == nameof(FreshwaterFish))
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == nameof(SaltwaterFish))
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }
            IAquarium aquarium = this.aquariums.First(a => a.Name == aquariumName);
            ////
            string outputMsg = string.Empty;

            if (aquarium.GetType() == typeof(FreshwaterAquarium) && fish.GetType() == typeof(FreshwaterFish) ||
                aquarium.GetType() == typeof(SaltwaterAquarium) && fish.GetType() == typeof(SaltwaterFish))
            {
                outputMsg = string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName);
                aquarium.AddFish(fish);
            }
            else
            {
                outputMsg = OutputMessages.UnsuitableWater;
            }
            //if (fish.GetType() == typeof(FreshwaterFish) && aquarium.GetType() == typeof(SaltwaterAquarium))
            //{
            //    return OutputMessages.UnsuitableWater;
            //}
            //if (fish.GetType() == typeof(SaltwaterFish) && aquarium.GetType() == typeof(FreshwaterAquarium))
            //{
            //    return OutputMessages.UnsuitableWater;
            //}

            //aquarium.AddFish(fish);

            //string outputMsg = string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName);
            return(outputMsg);
        }
예제 #23
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            bool successfullyAdded = false;

            IAquarium aquarium = aquariums.First(x => x.Name == aquariumName);

            IFish fish = null;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            if (fish.GetType().Name == "FreshwaterFish" && aquarium.GetType().Name == "FreshwaterAquarium")
            {
                successfullyAdded = true;
            }
            else if (fish.GetType().Name == "SaltwaterFish" && aquarium.GetType().Name == "SaltwaterAquarium")
            {
                successfullyAdded = true;
            }

            if (successfullyAdded)
            {
                aquarium.AddFish(fish);
            }

            return(successfullyAdded
                ? string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)
                : OutputMessages.UnsuitableWater);
        }
예제 #24
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish     fish;
            IAquarium aquarium = aquariums.FirstOrDefault(a => a.Name == aquariumName);

            //Type t = aquarium.GetType();
            //List<Aquarium> a = new List<Aquarium>();


            //foreach (var aq in aquariums)
            //{
            //    a.Add((Aquarium)aq);
            //}

            switch (fishType)
            {
            case "FreshwaterFish":
                fish = new FreshwaterFish(fishName, fishSpecies, price);
                break;

            case "SaltwaterFish":
                fish = new SaltwaterFish(fishName, fishSpecies, price);
                break;

            default: throw new InvalidOperationException(ExceptionMessages.InvalidFishType);
            }

            if ((fish.GetType().Name == "FreshwaterFish" && aquarium.GetType().Name == "FreshwaterAquarium") ||
                (fish.GetType().Name == "SaltwaterFish" && aquarium.GetType().Name == "SaltwaterAquarium"))
            {
                aquarium.AddFish(fish);
                return(string.Format(OutputMessages.EntityAddedToAquarium, fish.GetType().Name, aquariumName));
            }
            else
            {
                return(OutputMessages.UnsuitableWater);
            }
        }
예제 #25
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish = null;

            if (fishType == nameof(FreshwaterFish))
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == nameof(SaltwaterFish))
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException(Utilities.Messages.ExceptionMessages.InvalidFishType);
            }

            IAquarium aquarium = aquariums[aquariumName];

            if (aquarium.GetType().Name == nameof(FreshwaterAquarium))
            {
                if (fishType == "SaltwaterFish")
                {
                    return(Utilities.Messages.OutputMessages.UnsuitableWater);
                }
            }

            if (aquarium.GetType().Name == nameof(SaltwaterAquarium))
            {
                if (fishType == "FreshwaterFish")
                {
                    return(Utilities.Messages.OutputMessages.UnsuitableWater);
                }
            }

            aquarium.AddFish(fish);
            return(string.Format(Utilities.Messages.OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
        }
예제 #26
0
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish = null;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }

            if (fish == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidFishType));
            }

            IAquarium aquarium = this.aquariums.FirstOrDefault(x => x.Name == aquariumName);

            string result = string.Empty;

            if (aquarium.GetType().Name.StartsWith("Freshwater") != (fish.GetType().Name == "FreshwaterFish"))
            {
                result = string.Format(OutputMessages.UnsuitableWater);
            }
            else if (aquarium.GetType().Name.StartsWith("Saltwater") != (fish.GetType().Name == "SaltwaterFish"))
            {
                result = string.Format(OutputMessages.UnsuitableWater);
            }
            else
            {
                aquarium.AddFish(fish);
                result = string.Format(OutputMessages.FishAdded, fishType, aquariumName);
            }

            return(result);
        }
        public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)
        {
            IFish fish = null;

            if (fishType == "FreshwaterFish")
            {
                fish = new FreshwaterFish(fishName, fishSpecies, price);
            }
            else if (fishType == "SaltwaterFish")
            {
                fish = new SaltwaterFish(fishName, fishSpecies, price);
            }
            else
            {
                throw new InvalidOperationException
                          (Utilities.Messages.ExceptionMessages.InvalidFishType);
            }

            IAquarium aquarium = this.aquariums.FirstOrDefault(a => a.Name == aquariumName);

            if (aquarium == null)
            {
                throw new InvalidOperationException
                          (Utilities.Messages.ExceptionMessages.InvalidAquariumType);
            }

            if (IsWaterSuitable(fish, aquarium))
            {
                aquarium.AddFish(fish);
                return(string.Format(Utilities.Messages
                                     .OutputMessages.EntityAddedToAquarium, fishType, aquariumName));
            }
            else
            {
                return("Water not suitable.");
            }
        }