Пример #1
0
        // To protect from overposting attacks, please 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());
            }

            var json = JsonConvert.SerializeObject(Aufgaben);
            var data = new StringContent(json, Encoding.UTF8, "application/json");
            var url  = "https://localhost:44349/api/Aufgaben/" + Aufgaben.Id;

            using var client = new HttpClient();

            var response = await client.PutAsync(url, data); //api/Aufgabens/5

            string result = response.Content.ReadAsStringAsync().Result;

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

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, please 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(Aufgaben).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
Пример #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://localhost:44349/api/Aufgaben/" + id))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    Aufgaben = JsonConvert.DeserializeObject <Aufgaben>(apiResponse);
                }
            }

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

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, please 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.Aufgaben.Add(Aufgaben);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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