示例#1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(Category.CategoryId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Category = await _context.Categories.FindAsync(id);

            if (Category != null)
            {
                IQueryable <Ticket> ticketsIQ = from s in _context.Ticket
                                                select s;
                var IssueTickets = ticketsIQ.Where(a => a.CategoryId == Category.CategoryId).AsNoTracking();
                if (!IssueTickets.Any())
                {
                    _context.Categories.Remove(Category);
                    await _context.SaveChangesAsync();

                    TempData[DeleteStatus]  = "Success";
                    TempData[StatusMessage] = "Category has been deleted!";
                }
                else
                {
                    TempData[DeleteStatus]  = "Fail";
                    TempData[StatusMessage] = "Unable to delete category because it's still related to some Issue Tickets";
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Categories.Add(Category);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }