public async Task <IHttpActionResult> PuttReaction(int id, tReaction Reaction) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != Reaction.ID) { return(BadRequest()); } db.Entry(Reaction).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!tReactionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GettReaction(int id) { tReaction tReaction = await db.tReactions.FindAsync(id); if (tReaction == null) { return(NotFound()); } return(Ok(tReaction)); }
public async Task <IHttpActionResult> PosttReaction(tReaction Reaction) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tReactions.Add(Reaction); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = Reaction.ID }, Reaction)); }
public async Task <IHttpActionResult> DeletetReaction(int id) { tReaction tReaction = await db.tReactions.FindAsync(id); if (tReaction == null) { return(NotFound()); } db.tReactions.Remove(tReaction); await db.SaveChangesAsync(); return(Ok(tReaction)); }
private tUserAllergy UpdateAllergy(tUserAllergy userAllergy, Allergies newValues, Reaction userReaction, tCredential credentialObj, tSourceOrganization userSourceOrganization) { userAllergy.LastUpdateDateTime = DateTime.Now; //allergen name tAllergen allergenObj = db.tAllergens .Include("tAllergen1") .SingleOrDefault(x => x.Name == newValues.name); if (allergenObj == null) { allergenObj = new tAllergen(); allergenObj.Name = newValues.name; db.tAllergens.Add(allergenObj); db.SaveChanges(); } int tmpAllergyID = 0; if (allergenObj.ParentID != null) { tmpAllergyID = allergenObj.tAllergen1.ID; } else { tmpAllergyID = allergenObj.ID; } //allergen changed? if (userAllergy.AllergenID != tmpAllergyID) { //invalidate current and add new userAllergy.SystemStatusID = 4; return(CreateAllergy(new tUserAllergy(), newValues, userReaction, credentialObj, userAllergy.tUserSourceService, userAllergy.tSourceOrganization)); } else//same allergen { //status if (newValues.status != null) { tAllergyStatus allergyStatusObj = db.tAllergyStatuses .Include("tAllergyStatus1") .SingleOrDefault(x => x.Status == newValues.status); if (allergyStatusObj == null) { allergyStatusObj = new tAllergyStatus(); allergyStatusObj.Status = newValues.status; db.tAllergyStatuses.Add(allergyStatusObj); userAllergy.tAllergyStatus = allergyStatusObj; userAllergy.StatusID = allergyStatusObj.ID; } else //check to see if reaction has a mapped parent { if (allergyStatusObj.ParentID != null) { userAllergy.tAllergyStatus = allergyStatusObj.tAllergyStatus1; userAllergy.StatusID = allergyStatusObj.tAllergyStatus1.ID; } else { userAllergy.tAllergyStatus = allergyStatusObj; userAllergy.StatusID = allergyStatusObj.ID; } } } //severity if (newValues.severity != null) { tAllergySeverity allergySeverity = db.tAllergySeverities .Include("tAllergySeverity1") .SingleOrDefault(x => x.Severity == newValues.severity); if (allergySeverity == null) { allergySeverity = new tAllergySeverity(); allergySeverity.Severity = newValues.severity; db.tAllergySeverities.Add(allergySeverity); userAllergy.tAllergySeverity = allergySeverity; userAllergy.SeverityID = allergySeverity.ID; } else //check to see if reaction has a mapped parent { if (allergySeverity.ParentID != null) { userAllergy.tAllergySeverity = allergySeverity.tAllergySeverity1; userAllergy.SeverityID = allergySeverity.tAllergySeverity1.ID; } else { userAllergy.tAllergySeverity = allergySeverity; userAllergy.SeverityID = allergySeverity.ID; } } } //Dates if (newValues.dateRange.start != null && newValues.dateRange.start != DateTime.MinValue) { userAllergy.StartDateTime = newValues.dateRange.start; } if (newValues.dateRange.end != null && newValues.dateRange.end != DateTime.MinValue) { userAllergy.EndDateTime = newValues.dateRange.end; } //Allergy codes if (newValues.codes != null) { foreach (Codes code in newValues.codes) { if (code.code != null && code.codeSystem != null) { tCode AllergyCode = null; AllergyCode = db.tCodes .SingleOrDefault(x => x.Code == code.code && x.CodeSystem == code.codeSystem); if (AllergyCode == null) { AllergyCode = new tCode(); AllergyCode.Code = code.code; AllergyCode.CodeSystem = code.codeSystem; AllergyCode.CodeSystemName = code.codeSystemName; AllergyCode.Name = code.name; db.tCodes.Add(AllergyCode); db.SaveChanges(); } tXrefUserAllergiesCode userXrefAllergensCodes = null; userXrefAllergensCodes = db.tXrefUserAllergiesCodes .SingleOrDefault(x => x.CodeID == AllergyCode.ID && x.UserAllergiesID == userAllergy.ID); if (userXrefAllergensCodes == null) { userXrefAllergensCodes = new tXrefUserAllergiesCode(); userXrefAllergensCodes.tUserAllergy = userAllergy; userXrefAllergensCodes.tCode = AllergyCode; userXrefAllergensCodes.CodeID = AllergyCode.ID; userXrefAllergensCodes.UserAllergiesID = userAllergy.ID; db.tXrefUserAllergiesCodes.Add(userXrefAllergensCodes); } } } } } //reactions if (userReaction != null) { tReaction reactionObj = null; if (userReaction.reactionType.name != null) { reactionObj = db.tReactions .Include("tReaction1") .SingleOrDefault(x => x.Name == userReaction.reactionType.name); if (reactionObj == null) { reactionObj = new tReaction(); reactionObj.Name = userReaction.reactionType.name; reactionObj.ReactionTypeID = 1; //unspecified db.tReactions.Add(reactionObj); userAllergy.tReaction = reactionObj; userAllergy.ReactionID = reactionObj.ID; } else //check to see if reaction has a mapped parent { if (reactionObj.ParentID != null) { userAllergy.tReaction = reactionObj.tReaction1; userAllergy.ReactionID = reactionObj.tReaction1.ID; } else { userAllergy.tReaction = reactionObj; userAllergy.ReactionID = reactionObj.ID; } } } //Reaction codes if (userReaction.reactionType.codes != null) { foreach (Codes code in userReaction.reactionType.codes) { if (code.code != null && code.codeSystem != null) { tCode ReactionCode = null; ReactionCode = db.tCodes .SingleOrDefault(x => x.Code == code.code && x.CodeSystem == code.codeSystem); if (ReactionCode == null) { ReactionCode = new tCode(); ReactionCode.Code = code.code; ReactionCode.CodeSystem = code.codeSystem; ReactionCode.CodeSystemName = code.codeSystemName; ReactionCode.Name = code.name; db.tCodes.Add(ReactionCode); db.SaveChanges(); } tXrefReactionsCode userXrefReactionsCode = null; userXrefReactionsCode = db.tXrefReactionsCodes .SingleOrDefault(x => x.CodeID == ReactionCode.ID && x.ReactionID == reactionObj.ID); if (userXrefReactionsCode == null) { userXrefReactionsCode = new tXrefReactionsCode(); userXrefReactionsCode.tReaction = reactionObj; userXrefReactionsCode.tCode = ReactionCode; userXrefReactionsCode.CodeID = ReactionCode.ID; userXrefReactionsCode.ReactionID = reactionObj.ID; db.tXrefReactionsCodes.Add(userXrefReactionsCode); } } } } } return(userAllergy); }