Example #1
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var companyId = _userManager.GetUserId(User);

            Goal = await _context.Goal.Include(x => x.Reward).FirstOrDefaultAsync(x => x.ID == id && x.OwnerId == companyId);

            if (Goal != null)
            {
                _context.Remove(Goal.Reward);
                var actualGoals = _context.ActualGoalState.Include(x => x.Goal).Where(x => x.Goal.ID == id && x.Goal.OwnerId == companyId);
                _context.RemoveRange(actualGoals);
                _context.Goal.Remove(Goal);
                await _context.SaveChangesAsync();
            }

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