public List <AllergyModel> GetAllergyById(string userName) { AspNetUser user = _dbContext.AspNetUsers.SingleOrDefault(x => x.UserName == userName); int patientId = _dbContext.PatientMasters.Where(x => x.UserLoginDetailsId == user.Id).SingleOrDefault().Id; //List<PatientAllergy> patientAllergies = new List<PatientAllergy>(); List <AllergyModel> allergyModels = new List <AllergyModel>(); AllergyModel model; //patientAllergies = _dbContext.PatientAllergies.Where(x => x.PatientId == patientId).ToList(); var data = (from a in _dbContext.AllergyMasters join b in _dbContext.PatientAllergies on new { cond1 = a.Id.ToString() } equals new { cond1 = b.AllergyId.ToString() } where b.PatientId == patientId select new { id = a.Id, allergy = a.AllergyName, isfatal = b.FatalAllergy, patientid = b.PatientId }).ToList(); int i = 1; foreach (var item in data) { model = new AllergyModel { id = i++, allergy = item.allergy, isfatal = Convert.ToBoolean(item.isfatal), patientid = Convert.ToInt32(item.patientid) }; allergyModels.Add(model); } return(allergyModels); }
public ResultModel AddPatientAllergy(string userName, AllergyModel allergyModel) { ResultModel rs = new ResultModel(); //var patientId = from a in _dbContext.UserLoginDetails //.Where(x => x.Username == userName) // join b in _dbContext.PatientMasters // on new { cond1 = a.Id.ToString() } equals new { cond1 = b.UserLoginDetailsId } into lg // from p in lg.DefaultIfEmpty() // select new { Id = p.Id }; AspNetUser user = _dbContext.AspNetUsers.SingleOrDefault(x => x.UserName == userName); int patientId = _dbContext.PatientMasters.Where(x => x.UserLoginDetailsId == user.Id).SingleOrDefault().Id; PatientAllergy allergy = new PatientAllergy { PatientId = patientId, AllergyId = GetAllergyId(allergyModel.allergy), FatalAllergy = allergyModel.isfatal, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true }; _dbContext.PatientAllergies.Add(allergy); _dbContext.SaveChanges(); rs.Code = 1; rs.Response = "Allergy data saved successfully"; return(rs); }