public JsonResult Update(int keywordID, string products) { var jsonSuccessResult = new JsonSuccessResult(); try { string[] arrProducts = products.Split(','); var curList = ProductKeywords.GetByKeywordID(keywordID); foreach (var product in arrProducts) { int productID = Int32.Parse(product); if (!curList.Any(item => item.ProductID == productID && item.KeywordID == keywordID)) { var kp = new ProductKeyword { ProductID = productID, KeywordID = keywordID, LastUpdate = DateTime.Now }; ProductKeywords.Insert(kp); } else { curList.Remove(curList.Single(cls => cls.KeywordID == keywordID && cls.ProductID == productID)); } } foreach (var item in curList) { ProductKeywords.Delete(item.ID); } jsonSuccessResult.Success = true; } catch (Exception ex) { jsonSuccessResult.Errors = new string[] { ex.Message }; jsonSuccessResult.Success = false; } return(new JsonResult() { Data = jsonSuccessResult }); }
public JsonResult Get(int keywordID) { var jsonSuccessResult = new JsonSuccessResult(); try { var list = ProductKeywords.GetByKeywordID(keywordID); jsonSuccessResult.Data = list; jsonSuccessResult.Success = true; } catch (Exception ex) { jsonSuccessResult.Errors = new string[] { ex.Message }; jsonSuccessResult.Success = false; } return(new JsonResult() { Data = jsonSuccessResult }); }