public async Task <ActionResult <Child> > Post([FromBody] Child child)
        {
            _context.Children.Add(child);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", child));
        }
示例#2
0
        //[Authorize(Roles = "Admin")]
        public async Task <IActionResult> PutChild([FromRoute] int id, [FromBody] Child child)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != child.Id)
            {
                return(BadRequest());
            }

            _context.Entry(child).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChildExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            var child = await _db.Children.FindAsync(Child.ppsID);

            if (child != null)
            {
                _db.Children.Remove(child);
                await _db.SaveChangesAsync();
            }

            return(RedirectToPage("ListApplications"));
        }
示例#4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                _db.Children.Add(Child);
                await _db.SaveChangesAsync();

                MessageFull = $"Total Cost is €{Child.GetCostFull()} per week";
                MessageTemp = $"Total Cost is €{Child.GetCostTemp()} per week";
                return(RedirectToPage("ThankYou", new { id = Child.ppsID }));
            }

            else
            {
                return(Page());
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {   //Find number of days selected from individual bool days
                bool[] selectDays = { Child.Monday, Child.Tuesday, Child.Wednesday, Child.Thursday, Child.Friday };

                Child.DaysRequested = GetDays(selectDays);
                //add student tot he DB
                _db.Children.Add(Child);
                await _db.SaveChangesAsync();

                return(RedirectToPage("ListChild"));
            }
            else
            {
                return(Page());
            }
        }
示例#6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _db.Attach(Child).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw new Exception($"Child {Child.ppsID} not found!");
            }

            return(RedirectToPage("/ListApplications"));
        }