Пример #1
0
        public async Task <ActionResult <Citizen> > DeleteCitizen(long cpr)
        {
            var citizen =
                await _context.Citizens
                .Include(c => c.RespiteCareRoom)
                .ThenInclude(rcr => rcr.RespiteCareHome)
                .SingleOrDefaultAsync(c => c.CPR == cpr);

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

            citizen.RespiteCareRoom.IsAvailable = true;

            _context.Entry(citizen.RespiteCareRoom).State = EntityState.Modified;

            citizen.RespiteCareRoom.RespiteCareHome.AvailableRespiteCareRooms =
                citizen.RespiteCareRoom.RespiteCareHome.AvailableRespiteCareRooms + 1;

            _context.Entry(citizen.RespiteCareRoom.RespiteCareHome).State = EntityState.Modified;

            _context.Citizens.Remove(citizen);
            await _context.SaveChangesAsync();

            return(citizen);
        }
Пример #2
0
        public async Task <IActionResult> PutCitizen(long id, Citizen citizen)
        {
            if (id != citizen.CPR)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <ActionResult <ProgressReport> > PostProgressReport(CreateProgressReportViewModel cprvm)
        {
            ProgressReport progressReport = new ProgressReport
            {
                Date   = DateTime.Now,
                Title  = cprvm.Title,
                Report = cprvm.Report,
                ResponsibleCaretaker = cprvm.ResponsibleCaretaker,
                CitizenCPR           = cprvm.CPR
            };

            var citizen =
                await _context.Citizens
                .Include(c => c.CitizenOverview)
                .FirstOrDefaultAsync(c => c.CPR == cprvm.CPR);

            citizen.CitizenOverview.NumberOfReevaluations = citizen.CitizenOverview.NumberOfReevaluations + 1;

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


            await _context.ProgressReports.AddAsync(progressReport);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                if (ProgressReportExists(progressReport.Id))
                {
                    return(Conflict());
                }
                else
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            return(CreatedAtAction("PostProgressReport", new { id = progressReport.Date }, progressReport));
        }
Пример #4
0
        public async Task <ActionResult <Citizen> > PostCitizen(CreateCitizenViewModel ccvm)
        {
            Citizen citizen = new Citizen
            {
                FirstName = ccvm.FirstName,
                LastName  = ccvm.LastName,
                CPR       = ccvm.CPR
            };

            Relative relative = new Relative
            {
                FirstName   = ccvm.RelativeFirstName,
                LastName    = ccvm.RelativeLastName,
                PhoneNumber = ccvm.PhoneNumber,
                Relation    = ccvm.Relation,
                IsPrimary   = ccvm.IsPrimary,
                Citizen     = citizen
            };

            ResidenceInformation residenceInformation = new ResidenceInformation
            {
                StartDate            = ccvm.StartDate,
                ReevaluationDate     = ccvm.ReevaluationDate,
                PlannedDischargeDate = ccvm.PlannedDischargeDate,
                ProspectiveSituationStatusForCitizen = ccvm.ProspectiveSituationStatusForCitizen,
                Citizen = citizen
            };

            CitizenOverview citizenOverview = new CitizenOverview
            {
                CareNeed              = ccvm.CareNeed,
                PurposeOfStay         = ccvm.PurposeOfStay,
                NumberOfReevaluations = 0,
                Citizen = citizen
            };

            var respiteCareHomeTemp = await _context.RespiteCareHomes.FirstOrDefaultAsync(rch => rch.Name == ccvm.RespiteCareHomeName);

            respiteCareHomeTemp.AvailableRespiteCareRooms = (respiteCareHomeTemp.AvailableRespiteCareRooms - 1);
            _context.Entry(respiteCareHomeTemp).State     = EntityState.Modified;

            var rcrType = "";

            switch (ccvm.Type)
            {
            case 0:
                rcrType = "Alm. plejebolig";
                break;

            case 1:
                rcrType = "Demensbolig";
                break;
            }

            var availableRespiteCareRoom =
                await _context.RespiteCareRooms
                .FirstOrDefaultAsync(rcr => (rcr.Type == rcrType) &&
                                     (rcr.IsAvailable) &&
                                     (rcr.RespiteCareHomeName == ccvm.RespiteCareHomeName));

            availableRespiteCareRoom.CitizenCPR            = ccvm.CPR;
            availableRespiteCareRoom.IsAvailable           = false;
            _context.Entry(availableRespiteCareRoom).State = EntityState.Modified;

            await _context.Relatives.AddAsync(relative);

            await _context.ResidenceInformations.AddAsync(residenceInformation);

            await _context.CitizenOverviews.AddAsync(citizenOverview);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                if (CitizenExists(citizen.CPR))
                {
                    return(Conflict());
                }
                else
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            return(CreatedAtAction("PostCitizen", new { id = ccvm.CPR }, ccvm));
        }