public IActionResult Post([FromBody] Insurance insurance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingInsurance = (from a in _context.Insurance
                                     where a.InsuranceProvider == insurance.InsuranceProvider &&
                                     a.CustomerId == insurance.CustomerId
                                     select a);

            //if insurance exists, it won't create another
            if (existingInsurance.Count <Insurance>() > 0)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }
            _context.Insurance.Add(insurance);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (InsuranceExists(insurance.InsuranceId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            return(Ok(insurance));
        }
Exemple #2
0
        public IActionResult Post([FromBody] Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingCustomer = (from c in _context.Customer
                                    where c.CustUserName == customer.CustUserName
                                    select c);

            //if customer exists, it won't create another
            if (existingCustomer.Count <Customer>() > 0)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }

            _context.Customer.Add(customer);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CustomerExists(customer.CustomerId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            return(Ok(customer));
        }
Exemple #3
0
        public IActionResult Post([FromBody] Allergy allergy)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingAllergy = (from a in _context.Allergy
                                   where a.Name == allergy.Name &&
                                   a.CustomerId == allergy.CustomerId
                                   select a);

            //if allergy exists, it won't create another
            if (existingAllergy.Count <Allergy>() > 0)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }

            _context.Allergy.Add(allergy);

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (AllergyExists(allergy.AllergyId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            return(Ok(allergy));
        }
Exemple #4
0
        public IActionResult Post([FromBody] Physician physician)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingPhysician = (from a in _context.Physician
                                     where a.PhysicianName == physician.PhysicianName &&
                                     a.CustomerId == physician.CustomerId
                                     select a);

            //if physician exists, it won't create another
            if (existingPhysician.Count <Physician>() > 0)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }

            _context.Physician.Add(physician);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (PhysicianExists(physician.PhysicianId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            return(Ok(physician));
        }
        public IActionResult Post([FromBody] EmContact emContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingEmContact = (from a in _context.EmContact
                                     where a.EmContactName == emContact.EmContactName &&
                                     a.CustomerId == emContact.CustomerId
                                     select a);

            //if emContact exists, it won't create another
            if (existingEmContact.Count <EmContact>() > 0)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }

            _context.EmContact.Add(emContact);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (EmContactExists(emContact.EmContactId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            return(Ok(emContact));
        }
Exemple #6
0
        public IActionResult Post([FromBody] MedicalCondition medicalCondition)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingMedicalCondition = (from a in _context.MedicalCondition
                                            where a.CustomerId == medicalCondition.CustomerId &&
                                            a.MedicalConditionName == medicalCondition.MedicalConditionName
                                            select a);

            //if medicalCondition exists, it won't create another
            if (existingMedicalCondition.Count <MedicalCondition>() > 0)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }

            _context.MedicalCondition.Add(medicalCondition);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (MedicalConditionExists(medicalCondition.MedicalConditionId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            return(Ok(medicalCondition));
        }
        public IActionResult Post([FromBody] MedicationPostView medicationPostView)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // checks to see if current drug exists
            var currentMedication = (from a in _context.Medication
                                     where a.BrandName == medicationPostView.BrandName &&
                                     a.Dosage == medicationPostView.Dosage
                                     select new Medication
            {
                MedicationId = a.MedicationId,
                GenericName = a.GenericName,
                BrandName = a.BrandName,
                Dosage = a.Dosage,
                SideEffects = a.SideEffects,
                DrugInteractions = a.DrugInteractions
            });

            //if medication exists, it will use current drug to create new Customer Medication
            if (currentMedication.Count <Medication>() > 0)
            {
                CustomerMed existingCustomerMed = new CustomerMed
                {
                    MedicationId     = medicationPostView.MedicationId,
                    CustomerId       = medicationPostView.CustomerId,
                    Usage            = medicationPostView.Usage,
                    Frequency        = medicationPostView.Frequency,
                    Notes            = medicationPostView.Notes,
                    ShowOnPublicView = medicationPostView.ShowOnPublicView,
                    CustUserName     = medicationPostView.CustUserName
                };

                _context.CustomerMed.Add(existingCustomerMed);
                _context.SaveChanges();

                return(Ok(medicationPostView));
            }

            //otherwise create new medication
            else
            {
                Medication medication = new Medication
                {
                    GenericName      = medicationPostView.GenericName,
                    BrandName        = medicationPostView.BrandName,
                    Dosage           = medicationPostView.Dosage,
                    SideEffects      = medicationPostView.SideEffects,
                    DrugInteractions = medicationPostView.DrugInteractions
                };

                _context.Medication.Add(medication);
                _context.SaveChanges();

                //get last medication added
                var newMed = currentMedication.Last();

                //use that medication ID to create new customerMed
                CustomerMed customerMed = new CustomerMed
                {
                    MedicationId     = newMed.MedicationId,
                    CustomerId       = medicationPostView.CustomerId,
                    Usage            = medicationPostView.Usage,
                    Frequency        = medicationPostView.Frequency,
                    Notes            = medicationPostView.Notes,
                    ShowOnPublicView = medicationPostView.ShowOnPublicView,
                    CustUserName     = medicationPostView.CustUserName
                };

                _context.CustomerMed.Add(customerMed);

                try
                {
                    _context.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    if (CustomerMedExists(customerMed.CustomerMedId))
                    {
                        return(new StatusCodeResult(StatusCodes.Status409Conflict));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(Ok(medicationPostView));
            }
        }