Exemple #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PetitionModelExists(PetitionModel.PetitionModelId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

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

            Petitioner pUser = await _userManager.GetUserAsync(User);

            var filename = Guid.NewGuid().ToString() + Path.GetExtension(PetitionPicture.FileName);
            var file     = Path.Combine(_environment.ContentRootPath, "wwwroot", "petition-photos", filename);

            using (var fileStream = new FileStream(file, FileMode.Create))
            {
                await PetitionPicture.CopyToAsync(fileStream);
            }
            InputPetitionModel.Photo           = filename;
            InputPetitionModel.PetitionModelId = Guid.NewGuid().ToString();
            InputPetitionModel.DateCreated     = DateTime.Now;
            InputPetitionModel.Status          = "In Progress";
            InputPetitionModel.Votes           = 1;
            InputPetitionModel.Creator         = pUser;

            _context.PetitionModel.Add(InputPetitionModel);
            await _context.SaveChangesAsync();

            return(RedirectToPage("/Index"));
        }
Exemple #3
0
        public async Task <IActionResult> OnPostAddSupportAsync()
        {
            CurrentUser = await _UserManager.GetUserAsync(User);

            string PetitionID = HttpContext.Session.GetString("PetitionID");

            HttpContext.Session.Remove("PetitionID");
            PetitionModel = await _context.PetitionModel.FirstOrDefaultAsync(m => m.PetitionModelId == PetitionID);

            PetitionModel.Votes++;
            _context.Support.Add(new Support {
                Supporter = CurrentUser, Petition = PetitionModel, SupportId = Guid.NewGuid().ToString()
            });
            await _context.SaveChangesAsync();

            return(RedirectToPage(new { id = PetitionID }));
        }
Exemple #4
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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