Esempio n. 1
0
        public PrimaryCareContactViewModel GetPrimaryCareContact(int PatientId, string UserId, bool isPharmixAdmin)
        {
            var result  = new PrimaryCareContactViewModel();
            var IsAdmin = false;

            if (IsAdminUser(UserId, isPharmixAdmin))
            {
                IsAdmin = true;
            }
            else
            {
                PatientId = _repository.GetContext().Patients.Where(p => p.UserId == UserId).Select(p => p.Id).FirstOrDefault();
            }

            var primaryCareContact = _repository.GetContext().PrimaryCareContact.Include(p => p.Pregnancy).Where(p => p.Pregnancy.PatientId == PatientId).FirstOrDefault();

            if (primaryCareContact == null)
            {
                result = new PrimaryCareContactViewModel();
            }
            else
            {
                result = Mapper.Map <PrimaryCareContactViewModel>(primaryCareContact);
            }

            result.IsAdmin   = IsAdmin;
            result.PatientId = PatientId;

            return(result);
        }
Esempio n. 2
0
        public bool SavePrimaryCareContact(PrimaryCareContactViewModel model, string UserId)
        {
            var result = false;

            try
            {
                var pregnancy = _repository.GetContext().Pregnancy.Where(p => p.PatientId == model.PatientId).FirstOrDefault();
                if (model.Id > 0)
                {
                    //Update Existing
                    var primaryCareContact = _repository.GetContext().PrimaryCareContact.Where(p => p.Id == model.Id).FirstOrDefault();
                    Mapper.Map(model, primaryCareContact);
                    primaryCareContact.SetUpdateDetails(UserId);

                    _repository.SaveExisting(primaryCareContact);
                }
                else
                {
                    //Add new Record
                    var primaryCareContact = new PrimaryCareContact();
                    Mapper.Map(model, primaryCareContact);
                    primaryCareContact.PregnancyId = pregnancy.Id;
                    primaryCareContact.SetCreateDetails(UserId);

                    var saveNew = _repository.SaveNew(primaryCareContact);
                }

                result = true;
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }