public Message UpdateRecord([FromBody] JToken value) { int doctorid = 0, personid = 0, medicalrecordid = 0; int.TryParse((string)value.SelectToken("doctorid"), out doctorid); int.TryParse((string)value.SelectToken("personid"), out personid); int.TryParse((string)value.SelectToken("medicalrecordid"), out medicalrecordid); if (!DoctorDAL.DoctorExists(doctorid)) { return(MessageHandler.Error("Incorrect doctorid. Not authorized to update patients")); } if (!PersonDAL.PersonExist(personid)) { return(MessageHandler.Error("Incorrect personid. Patient not found!")); } if (!MedicalDAL.RecordsExist(medicalrecordid)) { return(MessageHandler.Error("Incorrect medicalrecordid. Records not found!")); } string firstname = (string)value.SelectToken("firstname"); string lastname = (string)value.SelectToken("lastname"); string nationalid = (string)value.SelectToken("nationalid"); string gender = (string)value.SelectToken("gender"); string allergies = (string)value.SelectToken("allergies"); string medication = (string)value.SelectToken("medication"); DateTime dob = DateTime.MinValue; //if (! DateTime.TryParse((string)value.SelectToken("dateofbirth"), out dob)) //{ // dob = DateTime.MinValue; //} if (firstname == null) { return(MessageHandler.Error("You must enter a first name")); } if (lastname == null) { return(MessageHandler.Error("You must enter a last name")); } if (nationalid == null) { return(MessageHandler.Error("You must enter a valid National Identification number")); } // Update person record PersonDAL.UpdatePerson(personid, firstname, lastname, gender, dob, nationalid, (string)value.SelectToken("mobilenumber"), (string)value.SelectToken("homenumber"), (string)value.SelectToken("worknumber"), (string)value.SelectToken("address1"), (string)value.SelectToken("address2"), (string)value.SelectToken("city"), (string)value.SelectToken("country"), (string)value.SelectToken("email")); // Update medical record MedicalDAL.UpdateMedicalRecord(medicalrecordid, (string)value.SelectToken("allergies"), (string)value.SelectToken("medication"), (string)value.SelectToken("notes")); UserActivity.AddDoctorActivity((int)ActivityEnum.UpdateProfile, doctorid, (int)StatusEnum.Success, "Success", value.ToString()); return(MessageHandler.Success("Patient records updated successfully.")); }