Ejemplo n.º 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()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FounderExists(Founder.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 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(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Client.ClientType != "ИП")
            {
                if (JsonFounders != null)
                {
                    var missingRows = _context.Founders
                                      .Where(i => i.Client.ID == id);
                    _context.Founders.RemoveRange(missingRows);
                    _context.SaveChanges();

                    Client.Founders = JsonSerializer.Deserialize <ICollection <Founder> >(JsonFounders);
                }
            }
            else
            {
                JsonFounders = null;
            }
            _context.Attach(Client).State = EntityState.Modified;

            try
            {
                Client.ClientUpdatedDate = DateTime.Now;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientExists(Client.ID))
                {
                    return(NotFound());
                }
                else
                {
                    ErrorMessage = "Такой ИНН уже существует";
                    return(Page());
                }
            }

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