Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, PetBio petBio)
        {
            if (id != petBio.PetBioId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(petBio);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PetBioExists(petBio.PetBioId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["PetId"] = new SelectList(_context.PetAccounts, "PetAccountId", "PetAccountId", petBio.PetId);
            return(View(petBio));
        }
        public async Task <IActionResult> Edit(int id, [Bind("MedicalRecordId,PetId")] MedicalRecord medicalRecord)
        {
            if (id != medicalRecord.MedicalRecordId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(medicalRecord);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MedicalRecordExists(medicalRecord.MedicalRecordId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PetId"] = new SelectList(_context.PetAccounts, "PetAccountId", "PetAccountId", medicalRecord.PetId);
            return(View(medicalRecord));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, BlockedUsers blockedUsers)
        {
            if (id != blockedUsers.BlockedUserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(blockedUsers);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlockedUsersExists(blockedUsers.BlockedUserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PetAccountId"] = new SelectList(_context.PetAccounts, "PetAccountId", "PetAccountId", blockedUsers.BlockedUserId);
            return(View(blockedUsers));
        }
        public async Task <IActionResult> ConfirmAdoption(int id)
        {
            var request  = _context.adoptionRequests.Where(a => a.Id == id).FirstOrDefault();
            var animalId = request.AnimalId;

            if (request != null)
            {
                request.AdoptionStatus = "Approved";
            }
            try
            {
                _context.Update(request);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdoptionRequestExists(request.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            var animal = _context.Animal.Where(a => a.Id == animalId).FirstOrDefault();

            if (animal != null)
            {
                animal.IsAdopted = true; await _context.SaveChangesAsync();
            }
            //_context.adoptionRequests.Remove(request);
            var otherRequestsForSameAnimal = _context.adoptionRequests.Where(a => a.AnimalId == animal.Id).Where(a => a.AdoptionStatus == "Pending").ToList();

            foreach (var req in otherRequestsForSameAnimal)
            {
                req.AdoptionStatus = "Declined";
                _context.Update(req);
            }
            await _context.SaveChangesAsync();

            return(Ok());
        }