public List <ReferenceModel> GetTargetReferences(long id, long typeid, int version) { List <ReferenceModel> tmp = new List <ReferenceModel>(); EntityReferenceManager entityReferenceManager = new EntityReferenceManager(); EntityReferenceHelper helper = new EntityReferenceHelper(); try { // get all references where incoming is source var list = entityReferenceManager.References.Where(r => r.SourceId.Equals(id) && r.SourceEntityId.Equals(typeid) && r.SourceVersion <= version).ToList(); list.ForEach(r => tmp.Add(helper.Convert(r))); tmp.RemoveAll(item => item == null); } catch (Exception ex) { throw new Exception("References could not be loaded", ex); } finally { entityReferenceManager.Dispose(); } return(tmp); }
public JsonResult Delete(long id) { if (id == 0) { return(Json(false)); } EntityReferenceManager entityReferenceManager = new EntityReferenceManager(); try { //check if entity ref in db exist var entityRef = entityReferenceManager.References.FirstOrDefault(e => e.Id.Equals(id)); if (entityRef != null) { //check if user has rights to edit a dataset if (hasUserRights(entityRef.SourceId, entityRef.SourceEntityId, RightType.Write)) { entityReferenceManager.Delete(id); return(Json(true)); } else { return(Json("Error : " + "you are not authorized!")); } } } catch (Exception ex) { return(Json("Error : " + ex.Message)); } finally { entityReferenceManager.Dispose(); } return(Json(false)); }
public ActionResult Create(CreateSimpleReferenceModel model) { EntityReferenceHelper helper = new EntityReferenceHelper(); EntityReferenceManager entityReferenceManager = new EntityReferenceManager(); try { if (hasUserRights(model.SourceId, model.SourceTypeId, RightType.Write)) { SetViewData(model.SourceId, model.SourceTypeId, false, true); if (!ModelState.IsValid) { return(PartialView("_create", model)); } EntityReference entityReference = helper.Convert(model); entityReferenceManager.Create(entityReference); // if successfuly created a entity link return a json true return(Json(true)); } ModelState.AddModelError("", "you are not authorized!"); return(PartialView("_create", model)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message.ToString()); return(PartialView("_create", model)); } finally { entityReferenceManager.Dispose(); } }