public ActionResult Delete(Blog[] model) { JsonResultData data = new JsonResultData(); data.RunWithTry((resultData) => { foreach (var item in model) { _provider.Delete(item); } data.RedirectUrl = Url.Action("Index", ControllerContext.RequestContext.AllRouteValues().Merge("id", null)); }); return Json(data); }
private void SetCategories(Blog model, int[] categories) { if (categories != null && categories.Length > 0) { var categoryModels = _categoryProvider.CreateQuery().Where(it => categories.Contains(it.Id)).ToArray(); if (model.Categories == null) { model.Categories = categoryModels; } else { var removed = model.Categories.Where(it => !categories.Contains(it.Id)).ToArray(); foreach (var item in removed) { model.Categories.Remove(item); } foreach (var item in categoryModels) { if (!model.Categories.Any(it => item.Id == it.Id)) { model.Categories.Add(item); } } } } else { if (model.Categories != null) { model.Categories.Clear(); } } }