예제 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            //modifies the selected field in that database that has been changed and saves the database

            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString(SessionKeySitterID, Sitter.ID.ToString());/////
            }
            catch (DbUpdateConcurrencyException)
            {
                //if sitter does not exist then return not found else throw an exception

                if (!SitterExists(Sitter.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            //modifies the selected field in that database that has been changed and saves the database
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if pet does not exist then return not found else throw an exception
                if (!PetExists(Pet.PetID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
예제 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            Sitters = await _context.Sitter.ToListAsync();

            Bookings = await _context.Booking.ToListAsync();


            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!SocialMediaExists(SocialMedia.ID))
            {
                _context.Database.OpenConnection();
                try
                {
                    //add customer to the database and save changes
                    _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.SocialMedia ON");//set identity to on
                    _context.SocialMedia.Add(SocialMedia);
                    await _context.SaveChangesAsync();

                    _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.SocialMedia OFF");//set identity off
                }
                finally
                {
                    //close datbabase connection
                    _context.Database.CloseConnection();
                }
            }
            else
            {
                _context.Attach(SocialMedia).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            return(Page());
        }