Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ICollection <MedicineEntity> Read(MedicineEntity model)
 {
     try
     {
         string json              = File.ReadAllText(jsonFile);
         var    jObject           = JObject.Parse(json);
         JArray experiencesArrary = (JArray)jObject["medicines"];
         return(experiencesArrary.ToObject <List <MedicineEntity> >());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="model"></param>
        public void Add(MedicineEntity model)
        {
            try
            {
                string medicine        = JsonConvert.SerializeObject(model, Formatting.Indented);
                var    json            = File.ReadAllText(jsonFile);
                var    jsonObj         = JObject.Parse(json);
                var    medicinesArrary = jsonObj.GetValue("medicines") as JArray;
                var    newMedicine     = JObject.Parse(medicine);
                medicinesArrary.Add(newMedicine);
                jsonObj["medicines"] = medicinesArrary;

                string newJsonResult = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
                File.WriteAllText(jsonFile, newJsonResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
 public void Update(MedicineEntity model)
 {
     throw new NotImplementedException();
 }