public EntityReference Convert(CreateSimpleReferenceModel model)
        {
            EntityReference tmp = new EntityReference();

            tmp.SourceId       = model.SourceId;
            tmp.SourceEntityId = model.SourceTypeId;
            tmp.SourceVersion  = model.SourceVersion;
            tmp.TargetId       = model.Target;
            tmp.TargetEntityId = model.TargetType;
            tmp.TargetVersion  = model.TargetVersion;
            tmp.Context        = model.Context;
            tmp.ReferenceType  = model.ReferenceType;
            tmp.CreationDate   = DateTime.Now;

            return(tmp);
        }
        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();
            }
        }