public async Task <IActionResult> PutAdministrations(int id, AdministrationDTO administration)
        {
            if (id != administration.Id)
            {
                return(BadRequest());
            }

            var administrations = await _context.Administrations.FirstOrDefaultAsync(a => a.Id == id);

            administrations.medicationId = administration.Medication.Id;
            administrations.patientId    = administration.Patient.Id;
            administrations.dose         = administration.Dose;
            administrations.timeGiven    = administration.TimeGiven;

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

            return(NoContent());
        }
        public async Task <ActionResult <AdministrationDTO> > GetAdministrations(int id)
        {
            var administrations = await _context.Administrations
                                  .Include(a => a.patient)
                                  .Include(a => a.medication)
                                  .FirstOrDefaultAsync(a => a.Id == id);

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

            var admin = new AdministrationDTO
            {
                Medication = new MedicationDTO
                {
                    Id   = administrations.medicationId,
                    Name = administrations.medication.name
                },
                Patient = new PatientDTO
                {
                    Id         = administrations.patientId,
                    GivenName  = administrations.patient.firstName,
                    FamilyName = administrations.patient.familyName
                },
                Dose      = administrations.dose,
                TimeGiven = administrations.timeGiven
            };

            return(admin);
        }
        public async Task <ActionResult <AdministrationDTO> > DeleteAdministrations(int id)
        {
            var administrations = await _context.Administrations.FindAsync(id);

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

            var admin = new AdministrationDTO
            {
                Id         = id,
                Medication = new MedicationDTO
                {
                    Name = administrations.medication.name,
                    Id   = administrations.medicationId
                },
                Dose    = administrations.dose,
                Patient = new PatientDTO
                {
                    GivenName  = administrations.patient.firstName,
                    FamilyName = administrations.patient.familyName,
                    Id         = administrations.patientId
                },
                TimeGiven = administrations.timeGiven
            };

            _context.Administrations.Remove(administrations);
            await _context.SaveChangesAsync();

            return(admin);
        }
Ejemplo n.º 4
0
        public async Task <bool> UpdateAdministration(AdministrationDTO administration)
        {
            try
            {
                await _administrationsClient.PutAdministrationsAsync(administration.Id, administration);

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Couldn't update administration");
                Debug.WriteLine(ex.Message);
                return(false);
            }
        }
Ejemplo n.º 5
0
        public async Task <int> PostAdministration(AdministrationDTO administration)
        {
            try
            {
                var result = await _administrationsClient.PostAdministrationsAsync(administration);

                return(result.Id);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Couldn't create administration");
                Debug.WriteLine(ex.Message);
                return(0);
            }
        }
        public async Task <ActionResult <AdministrationDTO> > PostAdministrations(AdministrationDTO administration)
        {
            var admin = new Administrations
            {
                dose         = administration.Dose,
                medicationId = administration.Medication.Id,
                patientId    = administration.Patient.Id,
                timeGiven    = administration.TimeGiven
            };

            _context.Administrations.Add(admin);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAdministrations", new { id = admin.Id }, administration));
        }
Ejemplo n.º 7
0
        public ActionResult Login(AdministrationDTO admin)
        {
            if (string.IsNullOrWhiteSpace(admin.Password))
            {
                return(View());
            }
            if (string.IsNullOrWhiteSpace(admin.Name))
            {
                return(View());
            }

            bool IsAdmin = adminService.GetAdmin(admin);

            Session["IsAdmin"] = IsAdmin;
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 8
0
        public bool GetAdmin(AdministrationDTO administrator)
        {
            if (string.IsNullOrWhiteSpace(administrator.Name))
            {
                throw new ValidationException("Не установлено name", "");
            }
            if (string.IsNullOrWhiteSpace(administrator.Password))
            {
                throw new ValidationException("Не установлено password", "");
            }
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <Administration, AdministrationDTO>()).CreateMapper();
            var admin  = mapper.Map <IEnumerable <Administration>, List <AdministrationDTO> >(Database.Administartions.Find(d => d.Name == administrator.Name));

            if (admin == null)
            {
                throw new ValidationException("Администратор не найден", "");
            }
            return((administrator.Password.Trim()).Equals(admin[0].Password));
        }