예제 #1
0
        public ActionResult Show2(long sourceId, long sourceTypeId, int sourceVersion)
        {
            ReferencesModel       model  = new ReferencesModel();
            EntityReferenceHelper helper = new EntityReferenceHelper();

            model.Selected         = helper.GetSimpleReferenceModel(sourceId, sourceTypeId, sourceVersion);
            model.TargetReferences = helper.GetTargetReferences(sourceId, sourceTypeId, sourceVersion);
            model.SourceReferences = helper.GetSourceReferences(sourceId, sourceTypeId, sourceVersion);
            model.HasEditRights    = hasUserRights(sourceId, RightType.Write);

            return(View("Show", model));
        }
예제 #2
0
        public JsonResult GetTargetVersions(long id, long type)
        {
            EntityReferenceHelper helper = new EntityReferenceHelper();
            SelectList            tmp    = new SelectList(new List <SelectListItem>());

            if (id > 0)
            {
                tmp = helper.GetEntityVersions(id, type);
            }
            var tmpDecending = tmp.OrderByDescending(x => x.Value).ToList();

            return(Json(tmpDecending, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public ActionResult Create(long sourceId, long sourceTypeId)
        {
            if (hasUserRights(sourceId, sourceTypeId, RightType.Write))
            {
                EntityReferenceHelper helper = new EntityReferenceHelper();

                SetViewData(sourceId, sourceTypeId, true, false);

                return(PartialView("_create", new CreateSimpleReferenceModel(sourceId, sourceTypeId, helper.CountVersions(sourceId, sourceTypeId))));
            }

            return(null);
        }
예제 #4
0
        public JsonResult GetTargets(long id)
        {
            EntityReferenceHelper helper = new EntityReferenceHelper();
            List <SelectListItem> tmp    = new List <SelectListItem>();

            if (id > 0)
            {
                helper.GetEntities(id).ForEach(e => tmp.Add(new SelectListItem()
                {
                    Text = e.Title + " (" + e.Id + ")", Value = e.Id.ToString()
                }));
            }

            return(Json(tmp, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        //test
        private void SetViewData(long id, long type, bool init, bool isSuccess)
        {
            EntityReferenceHelper helper = new EntityReferenceHelper();

            // ViewData for Title
            ViewData["Title"]   = helper.GetEntityTitle(id, type);
            ViewData["Version"] = helper.CountVersions(id, type);
            // ViewData for enitity type list
            ViewData["TargetType"]    = helper.GetEntityTypes();
            ViewData["Target"]        = new SelectList(new List <SelectListItem>(), "Text", "Value");
            ViewData["TargetVersion"] = new SelectList(new List <SelectListItem>(), "Text", "Value");
            ViewData["ReferenceType"] = helper.GetReferencesTypes();
            //"This references is saved."
            if (isSuccess)
            {
                ViewData["Success"] = "This references is saved.";
            }

            ViewData["Init"] = init;
        }
예제 #6
0
        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();
            }
        }