Exemplo n.º 1
0
 public bool Delete(NinjaViewModel item)
 {
     using (var ctx = new DatabaseModelContainer()) {
         ctx.NinjaSet.Remove(ctx.NinjaSet.Find(item.Id) ?? new Ninja());
         ctx.SaveChanges();
         return(true);
     }
 }
        protected async Task ConfirmDelete_Click(bool deleteConfirmed)
        {
            if (deleteConfirmed == true)
            {
                await NinjaViewModel.DeleteNinja(Id);

                NavigationManager.NavigateTo("ninjas");
            }
        }
Exemplo n.º 3
0
 public bool Update(NinjaViewModel item)
 {
     using (var ctx = new DatabaseModelContainer()) {
         var ninja = ctx.NinjaSet.First(o => o.Id == item.Id);
         ninja.Gold = item.Gold;
         ninja.Name = item.Name;
         ctx.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 4
0
        public void TestAutoMapperNinja()
        {
            AutoMapperConfig.RegisterMappings();
            NinjaViewModel ninjaViewModel = new NinjaViewModel();

            ninjaViewModel.NinjaName = "Chimbinha";

            Ninja ninja = Mapper.Map <NinjaViewModel, Ninja>(ninjaViewModel);

            Assert.IsNotNull(ninja);
        }
Exemplo n.º 5
0
        public ActionResult Create()
        {
            NinjaViewModel vm = util.makeModel(null);

            //AlertMsg("Created Ninja", "test");
            if (!ModelState.IsValid)
            {
                vm = util.makeModel(null);
            }
            return(View(vm));
        }
Exemplo n.º 6
0
        public IActionResult Details(int id)
        {
            var entity = _ninjaRepository.GetById(id);

            var viewmodel = new NinjaViewModel()
            {
                Id = entity.Id, Name = entity.Name
            };

            return(View(viewmodel));
        }
Exemplo n.º 7
0
 public bool Add(NinjaViewModel item)
 {
     using (var ctx = new DatabaseModelContainer()) {
         ctx.NinjaSet.Add(new Ninja()
         {
             Gold = item.Gold,
             Name = item.Name
         });
         ctx.SaveChanges();
         return(true);
     }
 }
        protected override async Task OnInitializedAsync()
        {
            Random random = new Random();

            randomNumber = random.Next(0, BackgroundImages.Length);

            NinjaList = await NinjaViewModel.GetNinjaList();

            foreach (Ninja i in NinjaList)
            {
                i.Mystery = await MysteryViewModel.GetMystery(i.MysteryId);

                i.Attack = await AttackViewModel.GetAttack(i.AttackId);

                if (i.ChaseId1 != null)
                {
                    i.Chases[0] = await ChaseViewModel.GetChase((long)i.ChaseId1);
                }
                if (i.ChaseId2 != null)
                {
                    i.Chases[1] = await ChaseViewModel.GetChase((long)i.ChaseId2);
                }
                if (i.ChaseId3 != null)
                {
                    i.Chases[2] = await ChaseViewModel.GetChase((long)i.ChaseId3);
                }

                if (i.PassiveId1 != null)
                {
                    i.Passives[0] = await PassiveViewModel.GetPassive((long)i.PassiveId1);
                }
                if (i.PassiveId2 != null)
                {
                    i.Passives[1] = await PassiveViewModel.GetPassive((long)i.PassiveId2);
                }
                if (i.PassiveId3 != null)
                {
                    i.Passives[2] = await PassiveViewModel.GetPassive((long)i.PassiveId3);
                }
            }

            FilteredList = NinjaList;
        }
        public override IActionResult Details(int id)
        {
            var ninja     = _ninjaRepository.GetDetailed(id);
            var allArmour = ninja.EquippedArmour.Select(na => na.Armour).ToList();

            var ninjaModel = new NinjaViewModel
            {
                Name      = ninja.Name,
                Id        = ninja.Id,
                AllArmour = allArmour,
                Gold      = ninja.Gold,

                TotalStrength     = allArmour.Sum(armour => armour.Strength),
                TotalAgility      = allArmour.Sum(armour => armour.Agility),
                TotalIntelligence = allArmour.Sum(armour => armour.Intelligence),
                TotalArmourValue  = allArmour.Sum(armour => armour.Price),
            };

            return(View(ninjaModel));
        }
Exemplo n.º 10
0
        protected override async Task OnInitializedAsync()
        {
            NinjaList = await NinjaViewModel.GetNinjaList();

            foreach (Ninja i in NinjaList)
            {
                i.Mystery = await MysteryViewModel.GetMystery(i.MysteryId);

                i.Attack = await AttackViewModel.GetAttack(i.AttackId);

                if (i.ChaseId1 != null)
                {
                    i.Chases[0] = await ChaseViewModel.GetChase((long)i.ChaseId1);
                }
                if (i.ChaseId2 != null)
                {
                    i.Chases[1] = await ChaseViewModel.GetChase((long)i.ChaseId2);
                }
                if (i.ChaseId3 != null)
                {
                    i.Chases[2] = await ChaseViewModel.GetChase((long)i.ChaseId3);
                }

                if (i.PassiveId1 != null)
                {
                    i.Passives[0] = await PassiveViewModel.GetPassive((long)i.PassiveId1);
                }
                if (i.PassiveId2 != null)
                {
                    i.Passives[1] = await PassiveViewModel.GetPassive((long)i.PassiveId2);
                }
                if (i.PassiveId3 != null)
                {
                    i.Passives[2] = await PassiveViewModel.GetPassive((long)i.PassiveId3);
                }
            }

            FilteredList = NinjaList;
        }
Exemplo n.º 11
0
        protected override async Task OnInitializedAsync()
        {
            EditRoute = $"ninjas/edit/{Id}";

            NinjaModel = await NinjaViewModel.GetNinja(Id);

            NinjaModel.Mystery = await MysteryViewModel.GetMystery(NinjaModel.MysteryId);

            NinjaModel.Attack = await AttackViewModel.GetAttack(NinjaModel.AttackId);

            if (NinjaModel.ChaseId1 != null)
            {
                NinjaModel.Chases[0] = await ChaseViewModel.GetChase((long)NinjaModel.ChaseId1);
            }
            if (NinjaModel.ChaseId2 != null)
            {
                NinjaModel.Chases[1] = await ChaseViewModel.GetChase((long)NinjaModel.ChaseId2);
            }
            if (NinjaModel.ChaseId3 != null)
            {
                NinjaModel.Chases[2] = await ChaseViewModel.GetChase((long)NinjaModel.ChaseId3);
            }

            if (NinjaModel.PassiveId1 != null)
            {
                NinjaModel.Passives[0] = await PassiveViewModel.GetPassive((long)NinjaModel.PassiveId1);
            }
            if (NinjaModel.PassiveId2 != null)
            {
                NinjaModel.Passives[1] = await PassiveViewModel.GetPassive((long)NinjaModel.PassiveId2);
            }
            if (NinjaModel.PassiveId3 != null)
            {
                NinjaModel.Passives[2] = await PassiveViewModel.GetPassive((long)NinjaModel.PassiveId3);
            }
        }
Exemplo n.º 12
0
        public ActionResult Create(NinjaViewModel viewModel)
        {
            try
            {
                picMethod = new PictureMethod(_context);

                // the id of logged-in member
                var creatorId      = User.Identity.GetUserId();
                var clanSelected   = viewModel.Clan.ClanID;
                int genderSelected = viewModel.Gender.ID;

                //youtube vid link for imageupload section: https://www.youtube.com/watch?v=5L5W-AE-sEs
                string filename
                    = Path.GetFileNameWithoutExtension(viewModel.ImageFile.FileName);
                string extension
                    = Path.GetExtension(viewModel.ImageFile.FileName);
                string filename2DB;

                //save image name is unique to allow duplicate names (time/date inclusive in name)
                filename    = filename + DateTime.Now.ToString("yymmssfff") + extension;
                filename2DB = filename; // for saving
                filename    = Path.Combine(Server.MapPath("~/Images/"), filename);
                picMethod.SaveImage(viewModel, filename);

                var creator = _context.Users.Single(u => u.Id == creatorId);

                Ninja ninja = null;

                if (!filename.IsEmpty())
                {
                    ninja = new Ninja
                    {
                        Name       = viewModel.Name,
                        clanID     = clanSelected,
                        genderID   = genderSelected,
                        Age        = viewModel.Age,
                        Creator    = creator,
                        NinjaImage = "~/Images/" + filename2DB
                    };
                }
                else
                {
                    ninja = new Ninja
                    {
                        Name     = viewModel.Name,
                        clanID   = clanSelected,
                        genderID = genderSelected,
                        Age      = viewModel.Age,
                        Creator  = creator,
                    };
                }



                _context.Clans.Single(c => c.ClanID == ninja.clanID).Members++;

                //save changes to database
                _context.Ninjas.Add(ninja);
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                util.AlertMsg("Create ninja", "Failed: " + e.ToString());
                viewModel = util.makeModel("Repopulating NinjaViewModel...");
                util.AlertMsg("Message: ", viewModel.Message2View);
                return(View(viewModel));
            }

            //return RedirectToAction("Index", "Home");
            //not currently working
            string msg = string.Format("{0}, {1}, {2}, from the {3}",
                                       viewModel.Name,
                                       viewModel.Age,
                                       viewModel.Gender.gender,
                                       viewModel.Clan.ClanName);

            util.AlertMsg("Created Ninja...", msg);
            return(View("NinjaDisplay", util.CreateNinjaDisplay()));
        }