Пример #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommandEntityExists(CommandEntity.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> Delete(int id)
        {
            if (id == default)
            {
                return(BadRequest($"{id} is invalid"));
            }

            try
            {
                var entity = new Post {
                    Id = id
                };
                _appDataContext.Attach(entity);
                _appDataContext.Remove(entity);
                var result = await _appDataContext.SaveChangesAsync();

                if (result == 1)
                {
                    return(Ok($"{id} deleted successfully"));
                }
            }
            catch (Exception)
            {
                // log error
            }

            return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }
Пример #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            Team.ExPts = 0;
            if (Team.Latched == true)
            {
                Team.ExPts += 30;
            }
            if (Team.Sampling == true)
            {
                Team.ExPts += 25;
            }
            if (Team.TeamMarker == true)
            {
                Team.ExPts += 15;
            }
            if (Team.Parking == true)
            {
                Team.ExPts += 10;
            }
            if (Team.EndLocation.ToLower().Contains("latched"))
            {
                Team.ExPts += 50;
            }
            else if (Team.EndLocation.ToLower().Contains("partial"))
            {
                Team.ExPts += 15;
            }
            else if (Team.EndLocation.ToLower().Contains("full"))
            {
                Team.ExPts += 25;
            }
            Team.ExPts += Team.DepotMinerals * 2;
            Team.ExPts += Team.GoldMinerals * 5;
            Team.ExPts += Team.SilverMinerals * 5;

            if (!ModelState.IsValid)
            {
                if (User.Identity.IsAuthenticated)
                {
                    return(Page());
                }
                return(RedirectToPage("/Error"));
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeamExists(Team.ID))
                {
                    return(NotFound());
                }
                throw;
            }

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