コード例 #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            //ensure that only updates on current auth user and the users for this service
            Service tmp = _context.Service.AsNoTracking().FirstOrDefault(s => s.Id == Service.Id);

            if (!(ModelState.IsValid &&
                  tmp.CaregiverId == Service.CaregiverId &&
                  Service.CaregiverId == _userManager.GetUserId(User) &&
                  Nullable.Compare <int>(Service.Rate, tmp.Rate) == 0 &&
                  String.Equals(tmp.CustomerComments, Service.CustomerComments)))
            {
                return(Page());
            }

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

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

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (LockoutEnd.HasValue)
            {
                AldeiaParentalUser = await _context.Users.FirstOrDefaultAsync(u => u.Id == AldeiaParentalUser.Id);

                AldeiaParentalUser.LockoutEnd = new DateTimeOffset(LockoutEnd.Value);
                ModelState.Clear();
                if (!TryValidateModel(AldeiaParentalUser))
                {
                    return(Page());
                }
                _context.Attach(AldeiaParentalUser).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
コード例 #4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            //ensure that only updates on current auth user
            PersonalDocument.UserId = _userManager.GetUserId(User);
            PersonalDocument old = await _context.PersonalDocument
                                   .AsNoTracking()
                                   .Where(p => p.UserId == _userManager.GetUserId(User))
                                   .Include(p => p.User)
                                   .FirstOrDefaultAsync(m => m.Id == PersonalDocument.Id);

            if (!String.Equals(old.DocumentNumber, PersonalDocument.DocumentNumber) ||
                !String.Equals(old.DocumentType, PersonalDocument.DocumentType) ||
                !String.Equals(old.FilePath, PersonalDocument.FilePath)
                )
            {
                PersonalDocument.Valid = null;
            }
            this.ModelState.Clear();
            if (!TryValidateModel(PersonalDocument))
            {
                return(Page());
            }

            if (Upload != null && Upload.ContentType.Equals("application/pdf") && Upload.Length <= 1000000)
            {
                string fileName = $"{PersonalDocument.UserId}_PersonalDocument_{DateTime.Now.ToString("yyyyMMddHHmmss")}.pdf";
                var    file     = Path.Combine(_environment.ContentRootPath, "uploads", fileName);
                using (var fileStream = new FileStream(file, FileMode.Create))
                {
                    await Upload.CopyToAsync(fileStream);

                    if (!String.IsNullOrEmpty(old.FilePath) &&
                        System.IO.File.Exists(Path.Combine(_environment.ContentRootPath, "uploads", old.FilePath)))
                    {
                        System.IO.File.Delete(Path.Combine(_environment.ContentRootPath, "uploads", old.FilePath));
                    }
                    PersonalDocument.FilePath = fileName;
                }
            }

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

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

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