/// <summary> /// this will update beer rating on basis of beer name /// </summary> /// <param name="data"></param> /// <returns></returns> public static bool UpdateBeerRating(BeerData data) { List <BeerData> recordToUpdate = null; List <BeerData> totalData = null; if (data != null && !string.IsNullOrEmpty(data.Name)) { var allJsonData = GetJsonValue(); totalData = DeSerilizeJson(allJsonData); recordToUpdate = (totalData != null && totalData.Count > 0)? totalData.FindAll(x => x.Name.ToLower() == data.Name.ToLower()):null; if (recordToUpdate != null && recordToUpdate.Count > 0) { foreach (var item in recordToUpdate) { item.Rating = data.Rating; } totalData.RemoveAll(x => x.Name.ToLower() == data.Name.ToLower()); totalData.AddRange(recordToUpdate); return(WriteJsonData(SerilizeJson(totalData))); } else { return(false); } } else { return(false); } }
public static bool PostNewBeer(BeerData data) { var allJsonData = GetJsonValue(); List <BeerData> finalResult = DeSerilizeJson(allJsonData); finalResult.Add(data); var convertedJson = SerilizeJson(finalResult); return(WriteJsonData(convertedJson)); }