Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the Zoo class.
        /// </summary>
        /// <param name="name">The name of the zoo.</param>
        /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
        /// <param name="restroomCapacity">The capacity of the zoo's restrooms.</param>
        /// <param name="animalFoodPrice">The price of a pound of food from the zoo's animal snack machine.</param>
        /// <param name="ticketPrice">The price of an admission ticket to the zoo.</param>
        /// <param name="boothMoneyBalance">The initial money balance of the zoo's ticket booth.</param>
        /// <param name="attendant">The zoo's ticket booth attendant.</param>
        /// <param name="vet">The zoo's birthing room vet.</param>
        /// <param name="waterBottlePrice"> The price of the zoo's water bottles.</param>
        public Zoo(string name, int capacity, int restroomCapacity, decimal animalFoodPrice, decimal ticketPrice, decimal boothMoneyBalance, Employee attendant, Employee vet, decimal waterBottlePrice)
        {
            this.animals            = new List <Animal>();
            this.animalSnackMachine = new VendingMachine(animalFoodPrice, new Account());
            this.b168        = new BirthingRoom(vet);
            this.capacity    = capacity;
            this.cages       = new List <Cage>();
            this.guests      = new List <Guest>();
            this.ladiesRoom  = new Restroom(restroomCapacity, Gender.Female);
            this.mensRoom    = new Restroom(restroomCapacity, Gender.Male);
            this.name        = name;
            this.ticketBooth = new MoneyCollectingBooth(attendant, ticketPrice, waterBottlePrice, new MoneyBox());
            this.ticketBooth.AddMoney(boothMoneyBalance);
            this.informationBooth = new GivingBooth(attendant);

            // Loop through the enumerator. Create a cage for every different type of animal.
            foreach (AnimalType a in Enum.GetValues(typeof(AnimalType)))
            {
                // Create a new cage and get the correct cage type.
                Cage cage = new Cage(400, 800, Animal.ConvertAnimalTypeToType(a));

                // Add the created cage to the list of cages.
                this.cages.Add(cage);
            }
        }
Exemple #2
0
        public IHttpActionResult GetRestroom(short id)
        {
            Restroom restStop = db.GetRestroom(id);

            if (restStop == null)
            {
                return(NotFound());
            }

            return(Ok(Models.Restroom.FromDataAccess(restStop)));
        }
Exemple #3
0
        public async Task <IHttpActionResult> GetRestroom(int id)
        {
            Log.Debug("GetRestroom called!");
            Restroom restroom = await Handler.GetRestroomAsync(id);

            if (restroom == null)
            {
                return(NotFound());
            }
            return(Ok(restroom));
        }
        internal async Task <Restroom> GetRestroomAsync(int restroomId)
        {
            Entity.Contact contact   = null;
            var            restroomD = await RestroomUnitOfWork.GetRestroomAsync(restroomId);

            if (restroomD != null && restroomD.ContactId.HasValue)
            {
                contact = RestroomUnitOfWork.GetById <Entity.Contact, int>(restroomD.ContactId.Value);
            }

            return(restroomD == null ? null : Restroom.FromDataAccess(restroomD, contact));
        }
Exemple #5
0
        static void BuildBalcony()
        {
            Balcony.Name = "阳台";
            Balcony.Alias.Clear();
            Balcony.IsWarm = false;

            Balcony.LightDescription =
                "小瓷砖铺成的地面在光照下异常耀眼。周围环绕着的金属栏杆增加着这里的狭小感。地面上有两个垃圾桶。你身后是回洗手间过道的移门。风声呼啸。";
            Balcony.Description =
                "没有灯光照明,阳台看上去只是模糊的剪影。你得小心点才不会碰到地上的两个垃圾桶。你身后是回洗手间过道的移门。风声呼啸。";
            Balcony.OnListen = (self, v, p) =>
            {
                Interactive.Print("你听见风的声音。");
                return(HandleResult.Continue);
            };

            Balcony.PostDescription = (self, v) =>
            {
                v.foundDarkness1 = true;
                return("");
            };

            AObject TrashBin = new AObject(
                "垃圾桶", new[] { "桶", "垃圾" },
                desc:           "看上去黑漆漆的。",
                ldesc:          "一个套着垃圾袋的垃圾桶,里面没有任何东西。",
                sinfo:          "一个垃圾桶")
            {
                IsTakable = true, IsContainer = true, Size = 30, Capacity = 20
            };

            AObject Darkness = new AObject(
                "黑暗", new string[0],
                desc:           "在黑暗中看着黑暗是一种怪异的体验。事实上它并不全是黑暗:它其实在发光,室内窗帘后的微光便是它发出的。看着它使你感到头晕。",
                ldesc:          "不像是雾,手电筒照不穿它。你只能形容它为“黑暗”:事实上它在发光,室内窗帘后的微光便是它发出的。但你看着它的时候你完全确定它就是一片黑暗,深不可测,使你头晕。")
            {
                Information = (s, v) => "栏杆外什么也没有,只是一片深深的、超现实的黑暗。"
            };

            AObject RestroomDoor = AObject.SimpleDoor(
                Restroom, "去洗手间过道的门", new string[]
                { "厕所门", "洗手间门", "厕所", "洗手间", "移门", "门" },
                desc:           "通往洗手间过道的移门。",
                flopside:       () => Restroom.FindObjectInternal("去阳台的移门"));

            Balcony.Objects.Clear();
            Balcony.Objects.AddRange(new[] { TrashBin, Darkness, RestroomDoor });

            Balcony.DefaultDoor = RestroomDoor;

            Balcony.Objects.Add(new AObject("墙壁", new string[]
                                            { "墙", "地面", "地板", "地", "柱子", "栏杆" }));
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the Zoo class.
 /// </summary>
 /// <param name="name">The name of the zoo.</param>
 /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
 /// <param name="restroomCapacity">The capacity of the zoo's restrooms.</param>
 /// <param name="animalFoodPrice">The price of a pound of food from the zoo's animal snack machine.</param>
 /// <param name="ticketPrice">The price of an admission ticket to the zoo.</param>
 /// <param name="boothMoneyBalance">The initial money balance of the zoo's ticket booth.</param>
 /// <param name="attendant">The zoo's ticket booth attendant.</param>
 /// <param name="vet">The zoo's birthing room vet.</param>
 /// <param name="waterBottlePrice"> The price of the zoo's water bottles.</param>
 public Zoo(string name, int capacity, int restroomCapacity, decimal animalFoodPrice, decimal ticketPrice, decimal boothMoneyBalance, Employee attendant, Employee vet, decimal waterBottlePrice)
 {
     this.animals = new List<Animal>();
     this.animalSnackMachine = new VendingMachine(animalFoodPrice);
     this.b168 = new BirthingRoom(vet);
     this.capacity = capacity;
     this.guests = new List<Guest>();
     this.ladiesRoom = new Restroom(restroomCapacity, "Female");
     this.mensRoom = new Restroom(restroomCapacity, "Male");
     this.name = name;
     this.ticketBooth = new Booth(attendant, ticketPrice, waterBottlePrice);
     this.ticketBooth.AddMoney(boothMoneyBalance);
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the Zoo class.
 /// </summary>
 /// <param name="name">The name of the zoo.</param>
 /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
 /// <param name="restroomCapacity">The capacity of the zoo's restrooms.</param>
 /// <param name="animalFoodPrice">The price of a pound of food from the zoo's animal snack machine.</param>
 /// <param name="ticketPrice">The price of an admission ticket to the zoo.</param>
 /// <param name="boothMoneyBalance">The initial money balance of the zoo's ticket booth.</param>
 /// <param name="attendant">The zoo's ticket booth attendant.</param>
 /// <param name="vet">The zoo's birthing room vet.</param>
 /// <param name="waterBottlePrice"> The price of the zoo's water bottles.</param>
 public Zoo(string name, int capacity, int restroomCapacity, decimal animalFoodPrice, decimal ticketPrice, decimal boothMoneyBalance, Employee attendant, Employee vet, decimal waterBottlePrice)
 {
     this.animals            = new List <Animal>();
     this.animalSnackMachine = new VendingMachine(animalFoodPrice, new Account());
     this.b168        = new BirthingRoom(vet);
     this.capacity    = capacity;
     this.guests      = new List <Guest>();
     this.ladiesRoom  = new Restroom(restroomCapacity, Gender.Female);
     this.mensRoom    = new Restroom(restroomCapacity, Gender.Male);
     this.name        = name;
     this.ticketBooth = new MoneyCollectingBooth(attendant, ticketPrice, waterBottlePrice, new MoneyBox());
     this.ticketBooth.AddMoney(boothMoneyBalance);
     this.informationBooth = new GivingBooth(attendant);
 }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the Zoo class.
        /// </summary>
        /// <param name="name">The name of the zoo.</param>
        /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
        /// <param name="restroomCapacity">The capacity of the zoo's restrooms.</param>
        /// <param name="animalFoodPrice">The price of a pound of food from the zoo's animal snack machine.</param>
        /// <param name="ticketPrice">The price of an admission ticket to the zoo.</param>
        /// <param name="boothMoneyBalance">The initial money balance of the zoo's ticket booth.</param>
        /// <param name="attendant">The zoo's ticket booth attendant.</param>
        /// <param name="vet">The zoo's birthing room vet.</param>
        /// <param name="waterBottlePrice"> The price of the zoo's water bottles.</param>
        public Zoo(string name, int capacity, int restroomCapacity, decimal animalFoodPrice, decimal ticketPrice, decimal boothMoneyBalance, Employee attendant, Employee vet, decimal waterBottlePrice)
        {
            this.animalSnackMachine = new VendingMachine(animalFoodPrice, new Account());
            this.b168        = new BirthingRoom(vet);
            this.capacity    = capacity;
            this.cages       = new List <Cage>();
            this.guests      = new List <Guest>();
            this.ladiesRoom  = new Restroom(restroomCapacity, Gender.Female);
            this.mensRoom    = new Restroom(restroomCapacity, Gender.Male);
            this.name        = name;
            this.ticketBooth = new MoneyCollectingBooth(attendant, ticketPrice, waterBottlePrice, new MoneyBox());
            this.ticketBooth.AddMoney(boothMoneyBalance);
            this.informationBooth = new GivingBooth(attendant);

            // Make a new list of aniamls and add them to the list.
            this.animals = new List <Animal>()
            {
                new Chimpanzee("Bobo", 10, 128.2, Gender.Male),
                new Chimpanzee("Bubbles", 3, 103.8, Gender.Female),
                new Dingo("Spot", 5, 41.3, Gender.Male),
                new Dingo("Maggie", 6, 37.2, Gender.Female),
                new Dingo("Toby", 0, 15.0, Gender.Male),
                new Eagle("Ari", 12, 10.1, Gender.Female),
                new Hummingbird("Buzz", 2, 0.02, Gender.Male),
                new Hummingbird("Bitsy", 1, 0.03, Gender.Female),
                new Kangaroo("Kanga", 8, 72.0, Gender.Female),
                new Kangaroo("Roo", 0, 23.9, Gender.Male),
                new Kangaroo("Jake", 9, 153.5, Gender.Male),
                new Ostrich("Stretch", 26, 231.7, Gender.Male),
                new Ostrich("Speedy", 30, 213.0, Gender.Female),
                new Platypus("Patti", 13, 4.4, Gender.Female),
                new Platypus("Bill", 11, 4.9, Gender.Male),
                new Platypus("Ted", 0, 1.1, Gender.Male),
                new Shark("Bruce", 19, 810.6, Gender.Female),
                new Shark("Anchor", 17, 458.0, Gender.Male),
                new Shark("Chum", 14, 377.3, Gender.Male),
                new Squirrel("Chip", 4, 1.0, Gender.Male),
                new Squirrel("Dale", 4, 0.9, Gender.Male)
            };

            // Loop through the enumerator. Create a cage for every different type of animal.
            foreach (AnimalType a in Enum.GetValues(typeof(AnimalType)))
            {
                // Create a new cage and get the correct cage type.
                Cage cage = new Cage(400, 800, Animal.ConvertAnimalTypeToType(a));

                // Add the created cage to the list of cages.
                this.cages.Add(cage);
            }
        }
Exemple #9
0
        public async Task <IHttpActionResult> PostRestroom(Restroom restroom)
        {
            if (!ModelState.IsValid)
            {
                Log.Warn("Model state is invalid in PostRestroom");
                return(BadRequest(ModelState));
            }
            Log.Debug("Before SaveRestroomAsync for public.");
            restroom.IsPublic = true;
            var result = await Handler.SaveRestroomAsync(restroom);

            Log.Debug("After SaveRestroomAsync for public.");

            return(Ok(result));
        }
        internal async Task <Restroom[]> GetRestroomsNearbyAsync(string routeAlpha, string direction, float?lat, float?longt, int?distance = null, bool publicRestrooms = true, bool pending = false)
        {
            var restrooms = await RestroomUnitOfWork.GetRestroomsNearbyAsync(routeAlpha, direction, lat, longt, distance, publicRestrooms, pending);

            var contactIds = restrooms.Where(m => m.ContactId.HasValue).Select(m => m.ContactId);
            var contacts   = RestroomUnitOfWork.Get <Entity.Contact>().Where(c => contactIds.Contains(c.ContactId));
            var result     = new List <Restroom>();

            foreach (var r in restrooms)
            {
                result.Add(Restroom.FromDataAccess(r, contacts.FirstOrDefault(c => c.ContactId == r.ContactId)));
            }
            //return result.Select(Restroom.FromDataAccess).ToArray();
            return(result.ToArray());
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the Zoo class.
        /// </summary>
        /// <param name="name">The name of the zoo.</param>
        /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
        /// <param name="restroomCapacity">The capacity of the zoo's restrooms.</param>
        /// <param name="animalFoodPrice">The price of a pound of food from the zoo's animal snack machine.</param>
        /// <param name="ticketPrice">The price of an admission ticket to the zoo.</param>
        /// <param name="waterBottlePrice">The price of a water bottle.</param>
        /// <param name="attendant">The zoo's ticket booth attendant.</param>
        /// <param name="vet">The zoo's birthing room vet.</param>
        public Zoo(string name, int capacity, int restroomCapacity, decimal animalFoodPrice, decimal ticketPrice, decimal waterBottlePrice, Employee attendant, Employee vet)
        {
            this.animals            = new List <Animal>();
            this.animalSnackMachine = new VendingMachine(animalFoodPrice, new MoneyBox());
            this.b168 = new BirthingRoom(vet);
            this.b168.OnTemperatureChange = (previousTemp, currentTemp) =>
            {
                this.OnBirthingRoomTemperatureChange(previousTemp, currentTemp);
            };
            this.capacity         = capacity;
            this.guests           = new List <Guest>();
            this.informationBooth = new GivingBooth(attendant);
            this.ladiesRoom       = new Restroom(restroomCapacity, Gender.Female);
            this.mensRoom         = new Restroom(restroomCapacity, Gender.Male);
            this.name             = name;
            this.ticketBooth      = new MoneyCollectingBooth(attendant, ticketPrice, waterBottlePrice, new MoneyBox());

            foreach (AnimalType at in Enum.GetValues(typeof(AnimalType)))
            {
                this.cages.Add(Animal.ConvertAnimalTypeToType(at), new Cage(400, 800));
            }

            this.AddAnimal(new Chimpanzee("Bobo", 10, 128.2, Gender.Male));
            this.AddAnimal(new Chimpanzee("Bubbles", 3, 103.8, Gender.Female));
            this.AddAnimal(new Dingo("Spot", 5, 41.3, Gender.Male));
            this.AddAnimal(new Dingo("Maggie", 6, 37.2, Gender.Female));
            this.AddAnimal(new Dingo("Toby", 0, 15.0, Gender.Male));
            this.AddAnimal(new Eagle("Ari", 12, 10.1, Gender.Female));
            this.AddAnimal(new Hummingbird("Buzz", 2, 0.02, Gender.Male));
            this.AddAnimal(new Hummingbird("Bitsy", 1, 0.03, Gender.Female));
            this.AddAnimal(new Kangaroo("Kanga", 8, 72.0, Gender.Female));
            this.AddAnimal(new Kangaroo("Roo", 0, 23.9, Gender.Male));
            this.AddAnimal(new Kangaroo("Jake", 9, 153.5, Gender.Male));
            this.AddAnimal(new Ostrich("Stretch", 26, 231.7, Gender.Male));
            this.AddAnimal(new Ostrich("Speedy", 30, 213.0, Gender.Female));
            this.AddAnimal(new Platypus("Patti", 13, 4.4, Gender.Female));
            this.AddAnimal(new Platypus("Bill", 11, 4.9, Gender.Male));
            this.AddAnimal(new Platypus("Ted", 0, 1.1, Gender.Male));
            this.AddAnimal(new Shark("Bruce", 19, 810.6, Gender.Female));
            this.AddAnimal(new Shark("Anchor", 17, 458.0, Gender.Male));
            this.AddAnimal(new Shark("Chum", 14, 377.3, Gender.Male));
            this.AddAnimal(new Squirrel("Chip", 4, 1.0, Gender.Male));
            this.AddAnimal(new Squirrel("Dale", 4, 0.9, Gender.Male));
        }
Exemple #12
0
        public async Task <IHttpActionResult> PostActRestroom(Restroom restroom)
        {
            Log.Debug("restroom:" + JsonConvert.SerializeObject(restroom));
            if (User == null)
            {
                return(Unauthorized());
            }
            var claimIdentity = User.Identity as ClaimsIdentity;
            var jobTitle      = claimIdentity?.Claims?.Where(m => m.Type == "JobTitle").FirstOrDefault()?.Value;
            var edit          = restroom.RestroomId > 0;

            if (jobTitle == null)
            {
                return(Unauthorized());
            }
            if (edit && !Config.JobTitlesAccessToEditRestroom.Any(m => m == jobTitle))
            {
                return(Unauthorized());
            }
            if (!edit && !Config.JobTitlesAccessToAddRestroom.Any(m => m == jobTitle))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                Log.Warn("Model state is invalid PostActRestroom");
                return(BadRequest(ModelState));
            }

            Log.Debug("Before SaveRestroomAsync for ACTransit");
            var result = await Handler.SaveRestroomAsync(restroom);

            Log.Debug("After SaveRestroomAsync for ACTransit");

            return(Ok(result));
        }
Exemple #13
0
        /// <summary>
        /// Initializes a new instance of the Zoo class.
        /// </summary>
        /// <param name="name">The name of the zoo.</param>
        /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
        /// <param name="restroomCapacity">The capacity of the zoo's restrooms.</param>
        /// <param name="animalFoodPrice">The price of a pound of food from the zoo's animal snack machine.</param>
        /// <param name="ticketPrice">The price of an admission ticket to the zoo.</param>
        /// <param name="waterBottlePrice">The price of the water bottles.</param>
        /// <param name="boothMoneyBalance">The initial money balance of the zoo's ticket booth.</param>
        /// <param name="attendant">The zoo's ticket booth attendant.</param>
        /// <param name="vet">The zoo's birthing room vet.</param>
        public Zoo(string name, int capacity, int restroomCapacity, decimal animalFoodPrice, decimal ticketPrice, decimal waterBottlePrice, decimal boothMoneyBalance, Employee attendant, Employee vet)
        {
            this.animals            = new List <Animal>();
            this.animalSnackMachine = new VendingMachine(animalFoodPrice, new Account());
            this.b168        = new BirthingRoom(vet);
            this.capacity    = capacity;
            this.guests      = new List <Guest>();
            this.ladiesRoom  = new Restroom(restroomCapacity, Gender.Female);
            this.mensRoom    = new Restroom(restroomCapacity, Gender.Male);
            this.name        = name;
            this.ticketBooth = new MoneyCollectingBooth(attendant, ticketPrice, waterBottlePrice, new MoneyBox());

            this.informationBooth = new GivingBooth(attendant);

            // ticketPrice added to boothMoneyBalance 1.2 step 9c.
            this.ticketBooth.AddMoney(boothMoneyBalance + ticketPrice);

            //// Object Initializer. Removed via Zoo 3.2 Step 3A.
            ////this.animals = new List<Animal>();
            ////{
            ////    new Chimpanzee("Bobo", 10, 128.2, Gender.Male);
            ////    new Chimpanzee("Bubbles", 3, 103.8, Gender.Female);
            ////    new Dingo("Spot", 5, 41.3, Gender.Male);
            ////    new Dingo("Maggie", 6, 37.2, Gender.Female);
            ////    new Dingo("Toby", 0, 15.0, Gender.Male);
            ////    new Eagle("Ari", 12, 10.1, Gender.Female);
            ////    new Hummingbird("Buzz", 2, 0.02, Gender.Male);
            ////    new Hummingbird("Bitsy", 1, 0.03, Gender.Female);
            ////    new Kangaroo("Kanga", 8, 72.0, Gender.Female);
            ////    new Kangaroo("Roo", 0, 23.9, Gender.Male);
            ////    new Kangaroo("Jake", 9, 153.5, Gender.Male);
            ////    new Ostrich("Stretch", 26, 231.7, Gender.Male);
            ////    new Ostrich("Speedy", 30, 213.0, Gender.Female);
            ////    new Platypus("Patti", 13, 4.4, Gender.Female);
            ////    new Platypus("Bill", 11, 4.9, Gender.Male);
            ////    new Platypus("Ted", 0, 1.1, Gender.Male);
            ////    new Shark("Bruce", 19, 810.6, Gender.Female);
            ////    new Shark("Anchor", 17, 458.0, Gender.Male);
            ////    new Shark("Chum", 14, 377.3, Gender.Male);
            ////    new Squirrel("Chip", 4, 1.0, Gender.Male);
            ////    new Squirrel("Dale", 4, 0.9, Gender.Male);
            //// }

            Animal brutus = new Dingo("Brutus", 3, 36.0, Gender.Male);
            Animal coco   = new Dingo("Coco", 7, 38.3, Gender.Female);

            coco.AddChild(brutus);

            Animal toby   = new Dingo("Toby", 4, 42.5, Gender.Male);
            Animal steve  = new Dingo("Steve", 4, 41.1, Gender.Male);
            Animal maggie = new Dingo("Maggie", 7, 34.8, Gender.Female);

            maggie.AddChild(toby);
            maggie.AddChild(steve);

            Animal lucy  = new Dingo("Lucy", 7, 36.5, Gender.Female);
            Animal ted   = new Dingo("Ted", 7, 39.7, Gender.Male);
            Animal bella = new Dingo("Bella", 10, 40.2, Gender.Female);

            bella.AddChild(coco);
            bella.AddChild(maggie);
            bella.AddChild(lucy);
            bella.AddChild(ted);

            List <Animal> tempList = new List <Animal>();

            tempList.Add(bella);
            tempList.Add(new Dingo("Max", 12, 46.9, Gender.Male));

            // Initializes a new Cage Dictionary.
            this.cages = new Dictionary <Type, Cage>();

            // Add new cages to the list for each animal.
            foreach (AnimalType t in Enum.GetValues(typeof(AnimalType)))
            {
                this.cages.Add(Animal.ConvertAnimalTypetoType(t), new Cage(400, 800));
            }

            this.AddAnimalsToZoo(tempList);
        }
Exemple #14
0
        /// <summary>
        /// Initializes a new instance of the Zoo class.
        /// </summary>
        /// <param name="name">The name of the zoo.</param>
        /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
        /// <param name="restroomCapacity">The capacity of the zoo's restrooms.</param>
        /// <param name="animalFoodPrice">The price of a pound of food from the zoo's animal snack machine.</param>
        /// <param name="ticketPrice">The price of an admission ticket to the zoo.</param>
        /// <param name="waterBottlePrice">The price of a water bottle.</param>
        /// <param name="boothMoneyBalance">The money balance of the money collecting booth.</param>
        /// <param name="attendant">The zoo's ticket booth attendant.</param>
        /// <param name="vet">The zoo's birthing room vet.</param>
        public Zoo(string name, int capacity, int restroomCapacity, decimal animalFoodPrice, decimal ticketPrice, decimal waterBottlePrice, decimal boothMoneyBalance, Employee attendant, Employee vet)
        {
            this.animals            = new List <Animal>();
            this.animalSnackMachine = new VendingMachine(animalFoodPrice, new Account());
            this.b168 = new BirthingRoom(vet);

            this.b168.OnTemperatureChange = (previousTemp, currentTemp) =>
            {
                if (this.OnBirthingRoomTemperatureChange != null)
                {
                    this.OnBirthingRoomTemperatureChange(previousTemp, currentTemp);
                }
            };

            this.capacity         = capacity;
            this.guests           = new List <Guest>();
            this.informationBooth = new GivingBooth(attendant);
            this.ladiesRoom       = new Restroom(restroomCapacity, Gender.Female);
            this.mensRoom         = new Restroom(restroomCapacity, Gender.Male);
            this.name             = name;
            this.ticketBooth      = new MoneyCollectingBooth(attendant, ticketPrice, waterBottlePrice, new MoneyBox());
            this.ticketBooth.AddMoney(boothMoneyBalance);

            foreach (AnimalType at in Enum.GetValues(typeof(AnimalType)))
            {
                Cage cage = new Cage(400, 800);
                cages.Add(Animal.ConvertAnimalTypeToType(at), cage);
            }

            // Animals for sorting
            this.AddAnimal(new Chimpanzee("Bobo", 10, 128.2, Gender.Male));
            this.AddAnimal(new Chimpanzee("Bubbles", 3, 103.8, Gender.Female));
            this.AddAnimal(new Dingo("Spot", 5, 41.3, Gender.Male));
            this.AddAnimal(new Dingo("Maggie", 6, 37.2, Gender.Female));
            this.AddAnimal(new Dingo("Toby", 0, 15.0, Gender.Male));
            this.AddAnimal(new Eagle("Ari", 12, 10.1, Gender.Female));
            this.AddAnimal(new Hummingbird("Buzz", 2, 0.02, Gender.Male));
            this.AddAnimal(new Hummingbird("Bitsy", 1, 0.03, Gender.Female));
            this.AddAnimal(new Kangaroo("Kanga", 8, 72.0, Gender.Female));
            this.AddAnimal(new Kangaroo("Roo", 0, 23.9, Gender.Male));
            this.AddAnimal(new Kangaroo("Jake", 9, 153.5, Gender.Male));
            this.AddAnimal(new Ostrich("Stretch", 26, 231.7, Gender.Male));
            this.AddAnimal(new Ostrich("Speedy", 30, 213.0, Gender.Female));
            this.AddAnimal(new Platypus("Patti", 13, 4.4, Gender.Female));
            this.AddAnimal(new Platypus("Bill", 11, 4.9, Gender.Male));
            this.AddAnimal(new Platypus("Ted", 0, 1.1, Gender.Male));
            this.AddAnimal(new Shark("Bruce", 19, 810.6, Gender.Female));
            this.AddAnimal(new Shark("Anchor", 17, 458.0, Gender.Male));
            this.AddAnimal(new Shark("Chum", 14, 377.3, Gender.Male));
            this.AddAnimal(new Squirrel("Chip", 4, 1.0, Gender.Male));
            this.AddAnimal(new Squirrel("Dale", 4, 0.9, Gender.Male));

            // Guests for sorting
            this.AddGuest(new Guest("Greg", 35, 100.0m, WalletColor.Crimson, Gender.Male, new Account()), new Ticket(0m, 0, 0));
            this.AddGuest(new Guest("Darla", 7, 10.0m, WalletColor.Brown, Gender.Female, new Account()), new Ticket(0m, 0, 0));
            this.AddGuest(new Guest("Anna", 8, 12.56m, WalletColor.Brown, Gender.Female, new Account()), new Ticket(0m, 0, 0));
            this.AddGuest(new Guest("Matthew", 42, 10.0m, WalletColor.Brown, Gender.Male, new Account()), new Ticket(0m, 0, 0));
            this.AddGuest(new Guest("Doug", 7, 11.10m, WalletColor.Brown, Gender.Male, new Account()), new Ticket(0m, 0, 0));
            this.AddGuest(new Guest("Jared", 17, 31.70m, WalletColor.Brown, Gender.Male, new Account()), new Ticket(0m, 0, 0));
            this.AddGuest(new Guest("Sean", 34, 20.50m, WalletColor.Brown, Gender.Male, new Account()), new Ticket(0m, 0, 0));
            this.AddGuest(new Guest("Sally", 52, 134.20m, WalletColor.Brown, Gender.Female, new Account()), new Ticket(0m, 0, 0));
        }
Exemple #15
0
        static void BuildDormitory12()
        {
            Dormitory12.Name = "你的寝室";
            Dormitory12.Alias.Clear();
            Dormitory12.Alias.AddRange(new[] { "寝室", "12#寝室", "12#" });

            Dormitory12.LightDescription =
                "这是你熟悉的寝室,闭上眼都能想象出它的样子。你能看见衣柜,桌子,床铺(四张:你睡在靠窗的下铺)以及通向走廊和洗手间过道的两扇门。";
            Dormitory12.Description =
                "你只能在黑暗中看见大概的轮廓:衣柜,桌子,床铺(四张:你睡在靠窗的下铺),以及通向走廊和洗手间过道的两扇门。\n\n现在仅有的照明是从窗帘后透出的一点微光。";
            Dormitory12.IsLit = false;

            // FIXME: do better than this
            AObject Clothes = new AObject(
                "衣服", new[] { "衣物", "服装" },
                desc:   "杂乱堆着的衣服;在顶上有几件外套和外裤。",
                ldesc:  "杂乱堆着的衣服;在顶上有几件外套和外裤。",
                info:   "打开的衣柜里能看见你杂乱堆放着的衣服。");

            AObject Closet = new AObject(
                "衣柜", new[] { "柜子", "橱柜", "柜门" },
                desc:   "普通的寝室衣柜,没有上锁。")
            {
                IsOpenable = true,
                OnOpening  = (self, v) =>
                {
                    self.OpenState = true;
                    v.currentRoom.Objects.Add(Clothes);
                    Print("你打开衣柜,里面杂乱地堆放着你的衣服。\n\n");
                    return(HandleResult.FullManaged);
                },
                OnClosing = (self, v) =>
                {
                    v.currentRoom.Objects.Remove(Clothes);
                    return(HandleResult.Continue);
                }
            };

            AObject Bottle = new AObject(
                "水杯", new[] { "水瓶", "杯子", "瓶子", "保温杯" },
                desc:   "它的金属表面握起来凉凉的。",
                ldesc:  "它银色的金属表面光滑发亮。",
                sinfo:  "一个水杯")
            {
                IsTakable = true, Size = 2f
            };

            AObject Flashlight = new AObject(
                "手电筒", new[] { "手电", "电筒" },
                desc:   "简单的手电筒,然而设计得十分周到,在黑暗中还会发出一小圈荧光。",
                ldesc:  "一个闪亮的银色金属手电筒。这花了你不少钱,但是挺漂亮,照明范围也大。",
                sinfo:  "一个小手电筒")
            {
                IsTakable   = true, IsSwitch = true, Size = 0.5f,
                OnTurningOn = (self, v) =>
                {
                    if (!v.inventory.Contains(self))
                    {
                        Print("你先得拿到它。\n\n");
                        return(HandleResult.Refused);
                    }
                    else if (!v.flashlightOK)
                    {
                        v.flashlightOK = true; self.SwitchState = true;
                        Print("咔哒。没有反应。难道是接触不良?\n\n");
                    }
                    else
                    {
                        self.SwitchState          = true;
                        v.currentRoom.IsPlayerLit = true;
                        if (!v.firstLight)
                        {
                            Print("咔哒。这次灯亮了,猛烈的白光使你一时间难以睁眼。不过令你欣慰的是你竟然没有惊动别人。一切看起来都在原位。\n\n");
                        }
                        else
                        {
                            Print("咔哒。灯亮了。\n\n");
                        }
                        v.firstLight = true;
                    }
                    return(HandleResult.FullManaged);
                },
                OnTurningOff = (self, v) =>
                {
                    if (!v.inventory.Contains(self))
                    {
                        Print("你先得拿到它。\n\n");
                        return(HandleResult.Refused);
                    }
                    else
                    {
                        self.SwitchState = false;
                        if (v.flashlightOK)
                        {
                            v.currentRoom.IsPlayerLit = false;
                        }
                        Print("咔哒。\n\n");
                        return(HandleResult.FullManaged);
                    }
                }
            };

            AObject ACControl = new AObject(
                "空调遥控器", new[] { "遥控器" },
                desc:   "一团方块形状的空调遥控器,按键在黑暗中微弱地发光。",
                ldesc:  "方块形状的白色空调遥控器,侧面带着红色条纹。",
                sinfo:  "一个空调遥控器")
            {
                IsTakable = true, Size = 0.3f
            };

            AObject Desk = new AObject(
                "桌子", new[] { "课桌", "桌椅" },
                desc:   "看上去漆黑一片,但是你知道自己的位置上有盏台灯,上面的格子里堆放着杂物。",
                ldesc:  "普通的桌子,从寝室一边的衣柜延伸到洗手间过道的门边。上面的格子里堆放着杂物。")
            {
                IsContainer = true, Capacity = 100
            };

            Desk.SubObjects.AddRange(new[] { Bottle, Flashlight, ACControl });

            AObject Lamp = new AObject(
                "台灯", new[] { "灯" },
                desc:   "虽然看不清楚,但是你至少知道开关在哪里。",
                ldesc:  "廉价的白色塑料台灯。如果能开,应该会挺亮的。")
            {
                IsSwitch    = true,
                OnTurningOn = (self, v) =>
                {
                    if (!v.foundLampUnlit)
                    {
                        Print("咔哒。没有反应。你突然明白过来,这个时候寝室里没有电源。于是你又把它关了。\n\n");
                        v.foundLampUnlit = true;
                    }
                    else
                    {
                        Print("咔哒。没有反应。\n\n");
                    }
                    return(HandleResult.Refused);
                },
                OnTaking = (self, v) =>
                {
                    Print("那东西的电线一直连到桌下,很不方便移动。\n\n");
                    return(HandleResult.Refused);
                }
            };

            AObject Beds = new AObject(
                "床铺", new[] { "床", "床位", "被子" },
                desc:   "看上去只是漆黑一片。",
                ldesc:  "床铺里面全都空无一人,被子随意铺开,就好像睡觉的人凭空消失了一样。床架、栏杆都非常完整,没有其他的痕迹。")
            {
                IsContainer  = true, Capacity = 300,
                OnExaminaion = (self, v) =>
                {
                    if (!v.foundNobody && (v.currentRoom.IsPlayerLit || v.currentRoom.IsLit))
                    {
                        string x = v.currentRoom.IsPlayerLit ? "手电筒的光束" : "视线";
                        Print(
                            "也许只是想确认一下,你打算看一眼床铺。当" + x + "聚焦在同学的床上时,有什么东西吓得你倒退了一步。最开始你不敢相信这是真的,但是无论怎么眨眼你看到的都是同一幅景象。\n\n");
                        v.foundNobody = true;
                    }
                    return(HandleResult.Continue);
                }
            };

            AObject AirConditioner = new AObject(
                "空调", new string[0],
                desc:   "空调制热模式低沉的呼吸声中,两个绿点随着在黑暗的高处闪光。",                 // can change
                ldesc:  "普通而标准的寝室空调,发出制热模式低沉的呼吸声。两个绿点微弱地在面板上亮着。")
            {
                IsSwitch    = true, SwitchState = true,
                IsReachable = false,
                OnTurningOn = (self, v) =>
                {
                    if (!v.inventory.Contains(ACControl))
                    {
                        Print("你没有拿遥控器。\n\n");
                        return(HandleResult.Refused);
                    }
                    self.Description = (_s, _v) =>
                                       "空调制热模式低沉的呼吸声中,两个绿点随着在黑暗的高处闪光。";
                    self.LightDescription = (_s, _v) =>
                                            "普通而标准的寝室空调,发出制热模式低沉的呼吸声。两个绿点微弱地在面板上亮着。";
                    Print("滴。导流板转动的僵硬声音。\n\n");
                    self.SwitchState = true;
                    return(HandleResult.FullManaged);
                },
                OnTurningOff = (self, v) =>
                {
                    if (!v.inventory.Contains(ACControl))
                    {
                        Print("你没有拿遥控器。\n\n");
                        return(HandleResult.Refused);
                    }
                    self.Description = (_s, _v) =>
                                       "看上去只是漆黑一片。";
                    self.LightDescription = (_s, _v) =>
                                            "普通而标准的寝室空调,毫无活力。";
                    Print("滴。导流板转动的僵硬声音。\n\n");
                    self.SwitchState = false;
                    return(HandleResult.FullManaged);
                }
            };

            AObject Window = new AObject(
                "窗户", new[] { "窗", "玻璃", "窗外", "天空", "外面" },
                desc:   "窗户被窗帘遮挡着,透出微弱的一点光。",
                ldesc:  "窗帘没有拉开,你看不见外面的样子。");

            AObject Darkness = new AObject(
                "黑暗", new[] { "窗外", "外面" },
                desc:   "在黑暗中看着黑暗是一种怪异的体验。事实上它并不全是黑暗:它其实在发光,室内窗帘后的微光便是它发出的。看着它使你感到头晕。",
                ldesc:  "不像是雾,手电筒照不穿它。你只能形容它为“黑暗”:事实上它在发光,室内窗帘后的微光便是它发出的。但你看着它的时候你完全确定它就是一片黑暗,深不可测,使你头晕。");

            AObject Curtain = new AObject(
                "窗帘", new[] { "帘子" },
                desc:   "从窗帘后面什么地方透出微弱的一点光来。",
                ldesc:  "浅黄的窗帘在灯光下显得苍白,遮蔽了窗外的一点点亮光。")                 // WILL CHANGE
            {
                IsOpenable = true, OpenState = false,
                OnOpening  = (self, v) =>
                {
                    self.OpenState        = true;
                    self.Description      = (_s, _v) => "窗帘被你拉开缩在一边,外面是一片黑暗。";
                    self.LightDescription = self.Description;
                    v.currentRoom.Objects.Remove(Window);
                    v.currentRoom.Objects.Add(Darkness);

                    if (!v.foundDarkness1)
                    {
                        Print(
                            "你拉开了窗帘。令你惊奇的是,后面根本就没有什么路灯在发光。事实上后面什么也没有:只是一片黑暗。\n\n");
                        v.foundDarkness1 = true;
                    }
                    else
                    {
                        Print(
                            "你拉开窗帘。窗帘外是一片黑暗。\n\n");
                    }
                    return(HandleResult.FullManaged);
                },
                OnClosing = (self, v) =>
                {
                    self.OpenState        = false;
                    self.Description      = (_s, _v) => "从窗帘后面什么地方透出微弱的一点光来。";
                    self.LightDescription = (_s, _v) => "浅黄的窗帘在灯光下显得苍白,遮蔽了窗外的一点点亮光。";
                    v.currentRoom.Objects.Remove(Darkness);
                    v.currentRoom.Objects.Add(Window);

                    Print("你拉上窗帘。\n\n");
                    return(HandleResult.FullManaged);
                }
            };

            Flashlight.Parent = Desk;
            Bottle.Parent     = Desk;
            ACControl.Parent  = Desk;

            AObject RestroomDoor = AObject.SimpleDoor(
                Restroom, "去洗手间过道的门",
                new[] { "厕所门", "洗手间门", "厕所", "洗手间", "门" },
                desc:   "通往洗手间过道的门。",
                flopside: () => Restroom.FindObjectInternal("去寝室的门"));

            AObject HallwayDoor = AObject.SimpleDoor(
                DormsHallway, "去走廊的门",
                new[] { "走廊门", "走廊", "门" },
                desc:   "通往寝室楼走廊的门。",
                flopside: () => DormsHallway.FindObjectInternal("12#寝室的门"));

            Dormitory12.Objects.Clear();
            Dormitory12.Objects.AddRange(new[] {
                Closet, Desk, Lamp, Beds, Window, Curtain, AirConditioner, RestroomDoor, HallwayDoor
            });
            Dormitory12.DefaultDoor = HallwayDoor;

            Dormitory12.Objects.Add(new AObject("椅子", new[]
                                                { "物品", "杂物", "枕头", "床单", "被子", "天花板", "东西", "床架", "栏杆",
                                                  "墙壁", "墙", "地面", "地板", "地" }));

            Area BedArea = new Area("床上")
            {
                OverrideDescription = (self, v) =>
                                      "躺在床上时,所有你能清楚看见的东西就是头顶的金属床板和一点栏杆。",
                FilterObject = (x) => ObjectVisibility.NotVisible
            };

            Dormitory12.Areas.Clear();
            Dormitory12.Areas.Add(BedArea);
            Dormitory12.CurrentArea = BedArea;

            Dormitory12.BeforeCommand = (self, v, p) =>
            {
                if (p == "起床" || p == "起来")
                {
                    if (self.CurrentArea == BedArea)
                    {
                        Print("你推开被子,试图让外部的空气刺激自己,但并没有什么用。最后你还是挣扎着坐了起来,摸索着穿上最近的一双拖鞋。在这个时候起来能干什么呢?还是走一圈再继续睡觉吧。\n\n");
                        self.CurrentArea = null;
                    }
                    else
                    {
                        Print("你并不在床上。\n\n");
                    }
                    self.PostCommand(self, v, p);
                    return(HandleResult.FullManaged);
                }
                else if (p == "睡" || p == "睡觉")
                {
                    Print($"{(self.CurrentArea == BedArea ? "" : "又一次走到床边躺下来之后,")}你被一种疲倦轻易地抓住了。你很快发现这很难逃脱——确切地说,你也不想要逃脱。闭上眼睛:这是多么美妙的动作,多么美好的感受啊!的确,你困了。你好像看见彩色的形状和线条在旋转,然后就睡着了。你没有再做梦。\n\n");
                    v.dreamStop  = true;
                    v.stopReason = "sleep";
                    self.PostCommand(self, v, p);
                    return(HandleResult.FullManaged);
                }
                else
                {
                    return(HandleResult.Continue);
                }
            };

            int acCounter = -1;

            Dormitory12.PostCommand = (self, v, p) =>
            {
                acCounter++;
                if (!AirConditioner.SwitchState)
                {
                    return(HandleResult.Continue);
                }
                switch (acCounter % 5)
                {
                case 0: Print(
                        "空调发出低沉的呼吸声,吐出温热的空气。\n\n"); break;

                case 1: Print(
                        "空调继续呼吸,声音变得更加急促。\n\n"); break;

                case 2: Print(
                        "空调平稳地呼吸。\n\n"); break;

                case 3: Print(
                        "空调仿佛打了个嗝,传来导流板转动的僵硬声音。咯吱。\n\n"); break;

                case 4: Print(
                        "空调的热气晃动着吹来。\n\n"); break;
                }
                return(HandleResult.Continue);
            };
        }
Exemple #16
0
        /// <summary>
        /// Initializes a new instance of the Zoo class.
        /// </summary>
        /// <param name="name">The name of the zoo.</param>
        /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
        /// <param name="restroomCapacity">The capacity of the zoo's restrooms.</param>
        /// <param name="animalFoodPrice">The price of a pound of food from the zoo's animal snack machine.</param>
        /// <param name="ticketPrice">The price of an admission ticket to the zoo.</param>
        /// <param name="boothMoneyBalance">The initial money balance of the zoo's ticket booth.</param>
        /// <param name="attendant">The zoo's ticket booth attendant.</param>
        /// <param name="vet">The zoo's birthing room vet.</param>
        /// <param name="waterBottlePrice"> The price of the zoo's water bottles.</param>
        public Zoo(string name, int capacity, int restroomCapacity, decimal animalFoodPrice, decimal ticketPrice, decimal boothMoneyBalance, Employee attendant, Employee vet, decimal waterBottlePrice)
        {
            this.animalSnackMachine = new VendingMachine(animalFoodPrice, new Account());
            this.b168 = new BirthingRoom(vet);

            // Plugs the HandleBirthingRoomTemperatureChange method into the delegate.
            this.b168.OnTemperatureChange += this.HandleBirthingRoomTemperatureChange;

            this.capacity    = capacity;
            this.cages       = new Dictionary <Type, Cage>();
            this.guests      = new List <Guest>();
            this.ladiesRoom  = new Restroom(restroomCapacity, Gender.Female);
            this.mensRoom    = new Restroom(restroomCapacity, Gender.Male);
            this.name        = name;
            this.ticketBooth = new MoneyCollectingBooth(attendant, ticketPrice, waterBottlePrice, new MoneyBox());
            this.ticketBooth.AddMoney(boothMoneyBalance);
            this.informationBooth = new GivingBooth(attendant);

            //// Make a new list of aniamls and add them to the list.
            this.animals = new List <Animal>();
            //{
            //    new Chimpanzee("Bubbles", 3, 103.8, Gender.Female),
            //    new Dingo("Spot", 5, 41.3, Gender.Male),
            //    new Dingo("Maggie", 6, 37.2, Gender.Female),
            //    new Dingo("Toby", 0, 15.0, Gender.Male),
            //    new Eagle("Ari", 12, 10.1, Gender.Female),
            //    new Hummingbird("Buzz", 2, 0.02, Gender.Male),
            //    new Hummingbird("Bitsy", 1, 0.03, Gender.Female),
            //    new Kangaroo("Kanga", 8, 72.0, Gender.Female),
            //    new Kangaroo("Roo", 0, 23.9, Gender.Male),
            //    new Kangaroo("Jake", 9, 153.5, Gender.Male),
            //    new Ostrich("Stretch", 26, 231.7, Gender.Male),
            //    new Ostrich("Speedy", 30, 213.0, Gender.Female),
            //    new Platypus("Patti", 13, 4.4, Gender.Female),
            //    new Platypus("Bill", 11, 4.9, Gender.Male),
            //    new Platypus("Ted", 0, 1.1, Gender.Male),
            //    new Shark("Bruce", 19, 810.6, Gender.Female),
            //    new Shark("Anchor", 17, 458.0, Gender.Male),
            //    new Shark("Chum", 14, 377.3, Gender.Male),
            //    new Squirrel("Chip", 4, 1.0, Gender.Male),
            //    new Squirrel("Dale", 4, 0.9, Gender.Male)
            //};

            // Loop through the enumerator. Create a cage for every different type of animal.
            foreach (AnimalType a in Enum.GetValues(typeof(AnimalType)))
            {
                // Create a new cage and get the correct cage type.
                Cage cage = new Cage(400, 800);

                // Add the created cage to the list of cages.
                this.cages.Add(Animal.ConvertAnimalTypeToType(a), cage);
            }

            //// Creates and adds lots of animals to their own lists of childern.
            //Animal brutus = new Dingo("Brutus", 3, 36.0, Gender.Male);
            //Animal coco = new Dingo("Coco", 7, 38.3, Gender.Female);
            //coco.AddChild(brutus);

            //Animal toby = new Dingo("Toby", 4, 42.5, Gender.Male);
            //Animal steve = new Dingo("Steve", 4, 41.1, Gender.Male);
            //Animal maggie = new Dingo("Maggie", 7, 34.8, Gender.Female);
            //maggie.AddChild(toby);
            //maggie.AddChild(steve);

            //Animal lucy = new Dingo("Lucy", 7, 36.5, Gender.Female);
            //Animal ted = new Dingo("Ted", 7, 39.7, Gender.Male);
            //Animal bella = new Dingo("Bella", 10, 40.2, Gender.Female);
            //bella.AddChild(coco);
            //bella.AddChild(maggie);
            //bella.AddChild(lucy);
            //bella.AddChild(ted);

            //List<Animal> tempList = new List<Animal>();
            //tempList.Add(bella);
            //tempList.Add(new Dingo("Max", 12, 46.9, Gender.Male));

            //// Call the recursive method.
            //this.AddAnimalsToZoo(tempList);
        }
        internal async Task <Restroom> SaveRestroomAsync(Restroom model)
        {
            Entity.Restroom restroom = null;
            if (model.RestroomId > 0)
            {
                var r = await RestroomUnitOfWork.GetRestroomAsync(model.RestroomId);

                restroom = model.ToDataAccessFrom(r);
                Logger.WriteDebug("SaveRestroomAsync->After GetRestroomAsync and ToDataAccessFrom:" + JsonConvert.SerializeObject(restroom));
            }
            else
            {
                restroom           = model.ToDataAccess();
                restroom.UpdUserId = CurrentUserName;
            }

            var hasContact     = false;
            var contactChanged = false;


            hasContact = !string.IsNullOrWhiteSpace(model.ContactName) ||
                         !string.IsNullOrWhiteSpace(model.ContactTitle) ||
                         !string.IsNullOrWhiteSpace(model.ContactEmail) ||
                         !string.IsNullOrWhiteSpace(model.ContactPhone);
            Entity.Contact contact = null;

            if (!hasContact && restroom.ContactId.HasValue && restroom.ContactId > 0)
            {
                restroom.ContactId = null;
                restroom.Contact   = null;
            }

            else if (restroom.ContactId.HasValue && restroom.ContactId > 0)
            {
                contact = await RestroomUnitOfWork.GetByIdAsync <Entity.Contact, int>(restroom.ContactId.Value);

                if (contact.ContactName != model.ContactName ||
                    contact.Title != model.ContactTitle ||
                    contact.Email != model.ContactEmail ||
                    contact.Phone != model.ContactPhone ||
                    contact.ServiceProvider != model.ServiceProvider
                    )
                {
                    contactChanged = true;
                }
            }

            if (contactChanged || (hasContact && (!restroom.ContactId.HasValue || restroom.ContactId == 0)))
            {
                contact = new Entity.Contact
                {
                    Title           = model.ContactTitle,
                    Email           = model.ContactEmail,
                    Phone           = model.ContactPhone,
                    ContactName     = model.ContactName,
                    ServiceProvider = model.ServiceProvider
                };
                contact          = RestroomUnitOfWork.Create(contact);
                restroom.Contact = contact;
            }


            //restroom.Active = true;
            restroom.StatusListId = 1;  // always pending...
            try
            {
                var savedModel = await RestroomUnitOfWork.SaveRestroomAsync(restroom);

                return(savedModel == null ? null : Restroom.FromDataAccess(savedModel));
            }
            catch (DbEntityValidationException ex)
            {
                var errTxt = ex.GetStringRepresentation();
                Logger.WriteError("RestroomHandler.SaveRestroomAsync.DbEntityValidationException -> EntityValidationErrors : \r\n" + errTxt);
                throw;
            }
        }
Exemple #18
0
        public async Task Add(Restroom item)
        {
            await _context.Restrooms.AddAsync(item);

            await _context.SaveChangesAsync();
        }