Exemplo n.º 1
0
        // [Bind(Include = "Id,Naam,Leeftijd,Centjes,Level,Gezondheid,Verveling,Levend")] Tamagotchi tamagotchi
        public ActionResult Create(TamagotchiModel tamagotchi)
        {
            if (ModelState.IsValid)
            {
                tamagotchi.Leeftijd   = 0;
                tamagotchi.Centjes    = 100;
                tamagotchi.Level      = 0;
                tamagotchi.Gezondheid = 100;
                tamagotchi.Verveling  = 0;
                tamagotchi.Levend     = 1;
                _tamagotchiRepository.Create(tamagotchi);
                _tamagotchiRepository.Save();
                return(RedirectToAction("Index"));
            }

            return(View(tamagotchi));
        }
Exemplo n.º 2
0
        // GET: Nacht
        public ActionResult Index()
        {
            List <TamagotchiModel> RoomlessTamagotchis = _tamagotchiRepository.GetAllAlive();

            _hotelkamerRepository.GetAll().Where(t => t.Tamagotchis.Count > 0).ToList().ForEach((h) =>
            {
                foreach (var objTamagotchi in h.Tamagotchis)
                {
                    for (int i = 0; i < RoomlessTamagotchis.Count; i++)
                    {
                        if (RoomlessTamagotchis[i].Id == objTamagotchi.Id)
                        {
                            RoomlessTamagotchis.Remove(RoomlessTamagotchis[i]);
                            i--;
                        }
                    }
                }
            });

            RoomlessTamagotchis.ForEach((t) =>
            {
                t.Verveling  += 20;
                t.Gezondheid -= 20;
                t.Leeftijd   += 1;
                t.Level      += 1;
                _tamagotchiRepository.Update(t);
            });
            _tamagotchiRepository.Save();

            _hotelkamerRepository.GetAll().Where(h => h.Tamagotchis.Count > 0).ToList().ForEach(k =>
            {
                IKamer kamer = Kamer.GetKamer(k.Type);
                kamer.Nacht(k.Tamagotchis.Select(t => new TamagotchiModel()
                {
                    _tamagotchi = t
                }).ToList());
                _hotelkamerRepository.Update(k);
                _hotelkamerRepository.Save();
                k.Tamagotchis.Clear();
                _hotelkamerRepository.Update(k);
                _hotelkamerRepository.Save();
            });

            TempData["NachtComplete"] = "Er is een nieuwe dag aangebroken!";

            return(RedirectToAction("Index", "Home"));
        }