Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Link")] AllLinkViewModel alvm)
        {
            if (id != alvm.Link.LinkNumber)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(alvm.Link);
                    await _context.SaveChangesAsync();

                    // I have no idea how to update the cache, so the hell with it, just refresh it completely.
                    await _cache.GetFromTable(true, _context.Links);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LinksmvccoreExists(alvm.Link.LinkNumber))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw new Exception("Could not save link #" + alvm.Link.LinkNumber + " but I have no idea why");
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            // This probably won't work because the binding omits people and bags.  Actually, the code shouldn't even get here
            return(View(alvm));
        }
Beispiel #2
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var alvm = new AllLinkViewModel();

            // Get all the links and find the one to delete
            alvm.Links = await _cache.GetFromTable(_context.Links);

            alvm.Link = alvm.Links.FirstOrDefault(m => m.LinkNumber == id);

            // Find the Person and Bag this link links
            alvm.People = await _cache.GetFromTable(_context.People);

            alvm.Person = alvm.People.FirstOrDefault(x => x.PersonNumber == alvm.Link.PersonId);
            alvm.Bags   = await _cache.GetFromTable(_context.Bags);

            alvm.Bag = alvm.Bags.FirstOrDefault(x => x.Id == alvm.Link.BagId);

            if (alvm.Link == null || alvm.Bag == null || alvm.Person == null)
            {
                return(NotFound("Invalid link: Link #" + alvm.Link.LinkNumber + " Person:" + alvm.Person.PersonNumber +
                                " Bag:" + alvm.Bag.Id));
            }

            return(View(alvm));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var alvm = new AllLinkViewModel();

            // Get all the links then find the one to edit
            alvm.Links = await _cache.GetFromTable(_context.Links);

            alvm.Link   = alvm.Links.FirstOrDefault(x => x.LinkNumber == id);
            alvm.People = await _cache.GetFromTable(_context.People);

            alvm.Person = alvm.People.FirstOrDefault(x => x.PersonNumber == alvm.Link.PersonId);
            alvm.Bags   = await _cache.GetFromTable(_context.Bags);

            alvm.Bag = alvm.Bags.FirstOrDefault(x => x.Id == alvm.Link.BagId);

            if (alvm.Link == null)
            {
                return(NotFound());
            }
            return(View(alvm));
        }
Beispiel #4
0
        public async Task <IActionResult> Index()
        {
            AllLinkViewModel alvm = new AllLinkViewModel();

            alvm.Links = await _cache.GetFromTable(_context.Links);

            alvm.People = await _cache.GetFromTable(_context.People);

            alvm.Bags = await _cache.GetFromTable(_context.Bags);

            alvm.Links = alvm.Links.OrderByDescending(x => x.LinkNumber).Take(10).ToList();
            return(View(alvm));
        }