コード例 #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()
        {
            var user = await _userManager.GetUserAsync(User);

            //setar o userId para o Id do Usuario da seção.
            Service.CaregiverId = user.Id;
            this.ModelState.Clear();
            if (!TryValidateModel(Service))
            {
                return(Page());
            }
            if (Service.datetime < (user.RegistrationDate ?? DateTime.Now))
            {
                IList <AldeiaParentalUser> customers = await _userManager.GetUsersInRoleAsync("Cliente");

                ViewData["Customer"] = new SelectList(customers.OrderBy(c => c.Email), "Id", "Email");
                ModelState.AddModelError(string.Empty, $"Informe a data do atendimento a partir de {(user.RegistrationDate??DateTime.Now).ToString("dd/MM/yyyy")}");
                return(Page());
            }

            if (Service.CaregiverId == null)
            {
                IList <AldeiaParentalUser> customers = await _userManager.GetUsersInRoleAsync("Cliente");

                ViewData["Customer"] = new SelectList(customers.OrderBy(c => c.Email), "Id", "Email");
                ModelState.AddModelError(string.Empty, $"Selecione o Cliente");
                return(Page());
            }

            _context.Service.Add(Service);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

            if (PersonalDocument != null)
            {
                if (PersonalDocument.UserId == _userManager.GetUserId(User) &&
                    !(PersonalDocument.Valid ?? false))
                {
                    if (!String.IsNullOrEmpty(PersonalDocument.FilePath) &&
                        System.IO.File.Exists(Path.Combine(_environment.ContentRootPath, "uploads", PersonalDocument.FilePath)))
                    {
                        System.IO.File.Delete(Path.Combine(_environment.ContentRootPath, "uploads", PersonalDocument.FilePath));
                    }
                    _context.PersonalDocument.Remove(PersonalDocument);
                    await _context.SaveChangesAsync();
                }
            }

            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()
        {
            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"));
        }
コード例 #5
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"));
        }
コード例 #6
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()
        {
            //setar o userId para o Id do Usuario da seção.
            PersonalDocument.UserId = _userManager.GetUserId(User);

            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);

                    PersonalDocument.FilePath = fileName;
                }
            }
            _context.PersonalDocument.Add(PersonalDocument);
            await _context.SaveChangesAsync();



            return(RedirectToPage("./Index"));
        }
コード例 #7
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"));
        }
コード例 #8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

            if (Service != null)
            {
                if (Service.CaregiverId == _userManager.GetUserId(User) &&
                    Service.Rate == null)
                {
                    _context.Service.Remove(Service);
                    await _context.SaveChangesAsync();
                }
            }

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