public async Task <IActionResult> PutEarnCategory(uint id, EarnCategory earnCategory)
        {
            // validate id value
            if (id == default)
            {
                return(BadRequest());
            }

            if (id != earnCategory.Id)
            {
                return(BadRequest());
            }

            Context.Entry(earnCategory).State = EntityState.Modified;

            try
            {
                await Context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await Context.EarnCategory.AnyAsync(e => e.Id == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult> PostEarnCategory(EarnCategory earnCategory)
        {
            // the name category should be unique
            if (await Context.EarnCategory.AnyAsync(x => x.Name == earnCategory.Name))
            {
                return(BadRequest("The name category should be unique."));
            }

            Context.EarnCategory.Add(earnCategory);
            await Context.SaveChangesAsync();

            return(Ok(new { id = earnCategory.Id }));
        }
Exemple #3
0
        public async Task <IActionResult> OnGetAsync(uint?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            EarnCategory = await _context.EarnCategory
                           .Include(e => e.User).FirstOrDefaultAsync(m => m.Id == id);

            if (EarnCategory == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #4
0
        public async Task <IActionResult> OnGetAsync(uint?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            EarnCategory = await _context.EarnCategory
                           .Include(e => e.User).FirstOrDefaultAsync(m => m.Id == id);

            if (EarnCategory == null)
            {
                return(NotFound());
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id");
            return(Page());
        }
Exemple #5
0
        public async Task <IActionResult> OnPostAsync(uint?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            EarnCategory = await _context.EarnCategory.FindAsync(id);

            if (EarnCategory != null)
            {
                _context.EarnCategory.Remove(EarnCategory);
                await _context.SaveChangesAsync();
            }

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