public bool CheckFollow(string username, int productId) { User target = _db.Users.FirstOrDefault(x => x.UserName == username); if (target != null) { FollowProduct fl = new FollowProduct(); fl.UserId = target.Id; fl.ProductId = productId; fl.Active = true; _db.FollowProducts.Add(fl); _db.SaveChanges(); return true; } return false; }
public static List<FollowProduct> GetFollowProductsFromServer(string request, Method method) { var products = new List<FollowProduct>(); var results = Request(request, method); try { JArray ja = JsonConvert.DeserializeObject<JArray>(results); foreach (var r in ja) { var c = (FollowProductApi)JsonConvert.DeserializeObject(r.ToString(), typeof(FollowProductApi)); var p = new FollowProduct(c); products.Add(p); } } catch (Exception ex1) { Console.WriteLine(ex1.ToString()); try { JObject r = JsonConvert.DeserializeObject<JObject>(results); var c = (FollowProductApi)JsonConvert.DeserializeObject(r.ToString(), typeof(FollowProductApi)); var p = new FollowProduct(c); products.Add(p); } catch (Exception ex2) { Console.WriteLine(ex2.ToString()); } } return products; }