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

            if (Image != null)
            {
                if (!Image.ContentType.Contains("image"))
                {
                    ModelState.AddModelError("Image", "File needs to be an image.");
                    return(Page());
                }

                var fileName = Utility.GetUniqueFileName(Image.FileName);
                var uploads  = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                var filePath = Path.Combine(uploads, fileName);
                Image.CopyTo(new FileStream(filePath, FileMode.Create));
                Campaign.LogoLocation = fileName; // Set the file name
            }

            _context.Campaigns.Add(Campaign);
            await _context.SaveChangesAsync();

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

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

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

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

            _context.Players.Add(Player);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            var player = _context.Players.Where(x => x.Id == Character.PlayerId).SingleOrDefault();

            if (player == null)
            {
                _logger.LogError("Player select list allowed user to select a player that doesn't exist.");
                throw new InvalidDataException();
            }

            Character.Player = player;

            if (Character.CampaignId != null)
            {
                var campaign = _context.Campaigns.Where(x => x.Id == Character.CampaignId).SingleOrDefault();
                if (campaign == null)
                {
                    _logger.LogError("Campaign select list allowed user to select a campaign that doesn't exist.");
                    throw new InvalidDataException();
                }

                Character.Campaign = campaign;
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Image != null)
            {
                if (!Image.ContentType.Contains("image"))
                {
                    ModelState.AddModelError("Image", "File needs to be an image.");
                    return(Page());
                }

                var fileName = Utility.GetUniqueFileName(Image.FileName);
                var uploads  = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                var filePath = Path.Combine(uploads, fileName);
                Image.CopyTo(new FileStream(filePath, FileMode.Create));
                Character.AvatarLocation = fileName; // Set the file name
            }

            _context.Characters.Add(Character);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Player = await _context.Players.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
Пример #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Campaign = await _context.Campaigns.FindAsync(id);

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

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

            if (Image != null)
            {
                if (!Image.ContentType.Contains("image"))
                {
                    ModelState.AddModelError("Image", "File needs to be an image.");
                    return(Page());
                }

                var fileName = Utility.GetUniqueFileName(Image.FileName);
                var uploads  = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                var filePath = Path.Combine(uploads, fileName);
                Image.CopyTo(new FileStream(filePath, FileMode.Create));
                Campaign.LogoLocation = fileName; // Set the file name
            }

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

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

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