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

            //Upload Photo
            var filename = Guid.NewGuid().ToString() + Path.GetExtension(ServiceImage.FileName);
            var file     = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "service-images", filename);

            using (var fileStream = new FileStream(file, FileMode.Create))
            {
                await ServiceImage.CopyToAsync(fileStream);
            }
            Service.Photo = filename;
            //Default values
            Service.DateCreated = DateTime.Now;
            Service.Status      = "Pending";
            Service.Votes       = 0;
            var currentUser = await _userManager.GetUserAsync(User);

            Service.CreatedBy = currentUser;
            _context.Service.Add(Service);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#2
0
        public async Task <IActionResult> OnPostVoteAsync(int ServiceId)
        {
            var currentUser = await _userManager.GetUserAsync(User);

            Service service = await _context.Service.FirstOrDefaultAsync(q => (q.ServiceId == ServiceId));

            Beneficiary cbc = await _context.Beneficiary.FirstOrDefaultAsync(q => (q.BeneficiaryId == currentUser.UserName));

            VoteLog vl_new = new VoteLog()
            {
                VoteLogId = Guid.NewGuid().ToString(), CorrService = service, Beneficiary = cbc
            };

            _context.VoteLog.Add(vl_new);
            service.Votes++;
            await _context.SaveChangesAsync();

            return(RedirectToPage(new { id = ServiceId }));
        }