public List <PrescriptionInfo> GetAll(string sortBy) { var prescriptionInfo = new List <PrescriptionInfo>(); using (var connection = new SqlConnection(conString)) using (var command = new SqlCommand()) { command.Connection = connection; command.CommandText = "select Name, Date, Date, DueDate, D.LastName as DoctorLastName, P.LastName as PatientLastName" + "from Prescription left join Doctor D on Prescription.IdPrescription = D.IdDoctor " + "Prescription left join Patient P on Prescription.IdPrescription = P.IdPatient " + $"order by {sortBy}"; connection.Open(); var dr = command.ExecuteReader(); while (dr.Read()) { var info = new PrescriptionInfo { Name = dr["Name"].ToString(), Date = DateTime.Parse(dr["Date"].ToString()), DueDate = DateTime.Parse(dr["DueDate"].ToString()), DoctorLastName = dr["DoctorLastName"].ToString(), PatientLastName = dr["PatientLastName"].ToString() }; prescriptionInfo.Add(info); } } return(prescriptionInfo); }
public Object PostUpdate2([FromBody] String strlymb_prescription) { //var recontent = Request.Content.ReadAsStringAsync().Result; //StreamReader reader = new StreamReader(request.GetRequestStream() ); //string recontent = reader.ReadToEnd(); var lymb_prescription = JsonConvert.DeserializeObject<PrescriptionDto>(strlymb_prescription); var result = getResult(lymb_prescription); using (var db = new BloggingContext()) { try { string msg=""; if (!checkPrescriptionid(lymb_prescription.prescriptionid, db,out msg)) { LogHelper.Default.WriteError(msg); result.accepted = false; result.message = msg; return result; } PrescriptionInfo preInfo = lymb_prescription.GetNewprescriptionInfo(); db.prescriptionInfo.Add(preInfo); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { throw ex; } var details = lymb_prescription.GetNewPrescriptionDetail(); db.prescriptionDetail.AddRange(details); db.SaveChanges(); var pharmacyId = lymb_prescription.pharmacyId; int state = 1; if (!String.IsNullOrEmpty(pharmacyId)) { state = db.Database.SqlQuery<int>("select state from lymb_prescription_state where pharmacyId='" + pharmacyId + "'").FirstOrDefault(); if (state != 2) { state = 1; } } result.state = state; return result; ; } catch (Exception e) { result.message = e.Message; //return JsonConvert.SerializeObject(result); LogHelper.Default.WriteError(e.Message,e); return result; } } }
public Object PostUpdate([FromBody] PrescriptionDto lymb_prescription) { var result = getResult(lymb_prescription); using (var db = new BloggingContext()) { try { PrescriptionInfo preInfo = lymb_prescription.GetNewprescriptionInfo(); db.prescriptionInfo.Add(preInfo); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { throw ex; } var details = lymb_prescription.GetNewPrescriptionDetail(); db.prescriptionDetail.AddRange(details); db.SaveChanges(); var pharmacyId = lymb_prescription.pharmacyId; int state = 1; if (!String.IsNullOrEmpty(pharmacyId)) { state = db.Database.SqlQuery<int>("select state from lymb_prescription_state where pharmacyId='" + pharmacyId+"'").FirstOrDefault(); if (state != 2) { state = 1; } } result.state = state; return result; ; } catch (Exception e) { result.message = e.Message; //return JsonConvert.SerializeObject(result); return result; } } }