public async Task <DonationCandidate> Update(DonationCandidate donationCandidate)
        {
            _donationDbContext.DonationCandidates.Update(donationCandidate);
            await _donationDbContext.SaveChangesAsync();

            return(donationCandidate);
        }
        public async Task <ActionResult <DonationCandidate> > PostCandidate(DonationCandidate candidate)
        {
            _context.DonationCandidates.Add(candidate);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCandidate", new { id = candidate.CandidateId }, candidate));
        }
        public async Task <ActionResult <DonationCandidate> > Create(DonationCandidate donationCandidate)
        {
            _context.DonationCandidates.Add(donationCandidate);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = donationCandidate.Id }));
        }
        public async Task <DonationCandidate> Add(DonationCandidate donationCandidate)
        {
            await _donationDbContext.DonationCandidates.AddAsync(donationCandidate);

            await _donationDbContext.SaveChangesAsync();

            return(donationCandidate);
        }
        public async Task <IActionResult> UpdateCandidate(int id, DonationCandidate donationCandidate)
        {
            donationCandidate.Id = id;

            try
            {
                await _donationCandidateService.UpdateCandidateAsync(id, donationCandidate);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_donationCandidateService.DonationCandidateExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(Ok());
        }
Ejemplo n.º 6
0
        public void Test_DonationCandidateModel()
        {
            // Instance of the DonationCandidate model to be tested
            DonationCandidate candidate = new DonationCandidate();

            // Assigning values to various fields of the model
            candidate.id         = 1;
            candidate.fullName   = "Emmanuel";
            candidate.mobile     = "+36708383747";
            candidate.age        = 25;
            candidate.bloodGroup = "O-";
            candidate.address    = "Szanto";

            // Assert to check for equality between assigned values and those store in the database
            Assert.Equal(1, candidate.id);
            Assert.Equal("Emmanuel", candidate.fullName);
            Assert.Equal("+36708383747", candidate.mobile);
            Assert.Equal(25, candidate.age);
            Assert.Equal("O-", candidate.bloodGroup);
            Assert.Equal("Szanto", candidate.address);
        }
        public async Task <ActionResult <DonationCandidate> > PostDonationCandidate(DonationCandidate donationCandidate)
        {
            _context.DonationCandidates.Add(donationCandidate);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (DonationCandidateExists(donationCandidate.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetDonationCandidate", new { id = donationCandidate.id }, donationCandidate));
        }
        public async Task <IActionResult> PutDonationCandidate(int id, DonationCandidate candidate)
        {
            candidate.Id = id;

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

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

                throw;
            }

            return(NoContent());
        }
        public async Task <ActionResult> Update(long id, DonationCandidate donationCandidate)
        {
            donationCandidate.Id = id;

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await _context.DonationCandidates.AnyAsync(x => x.Id == id))
                {
                    return(NotFound());
                }

                // Logger to add.
                throw;
            }

            return(NoContent());
        }
Ejemplo n.º 10
0
 public async Task AddCandidateAsync(DonationCandidate donationCandidate)
 {
     _context.DonationCandidates.Add(donationCandidate);
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 11
0
 public async Task DeleteCandidateAsync(DonationCandidate donationCandidate)
 {
     _context.DonationCandidates.Remove(donationCandidate);
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 12
0
 public async Task UpdateCandidateAsync(int id, DonationCandidate donationCandidate)
 {
     _context.Entry(donationCandidate).State = EntityState.Modified;
     await _context.SaveChangesAsync();
 }
        public async Task <ActionResult <DonationCandidate> > AddCandidate(DonationCandidate donationCandidate)
        {
            await _donationCandidateService.AddCandidateAsync(donationCandidate);

            return(Ok(donationCandidate.Id));
        }
        public async Task <ActionResult <DonationCandidate> > DeleteCandidate(int id, DonationCandidate donationCandidate)
        {
            var candidate = await _donationCandidateService.GetCandidateAsync(id);

            if (candidate == null)
            {
                return(NotFound());
            }


            await _donationCandidateService.DeleteCandidateAsync(donationCandidate);

            return(Ok(donationCandidate));
        }