public ActionResult AlbumPermission(List <int> From, List <int> To) { try { DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1(); var deleteuser = db.AlbumPermissions.Where(x => x.IsAuthorized == true).Select(o => o).ToList(); foreach (var deluser in deleteuser) { db.AlbumPermissions.DeleteObject(deluser); } db.SaveChanges(); for (int j = 0; j < To.Count(); j++) { DSRCManagementSystem.AlbumPermission objaccess = new DSRCManagementSystem.AlbumPermission(); objaccess.UserId = To[j]; objaccess.IsAuthorized = true; db.AddToAlbumPermissions(objaccess); db.SaveChanges(); } return(Json("Authorize", JsonRequestBehavior.AllowGet)); } catch (Exception Ex) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName); return(Json("Failed", JsonRequestBehavior.AllowGet)); } }