예제 #1
0
        // GET: Manager/Collections/Edit/5
        public ActionResult Edit(int?id, int?entityTypeId)
        {
            CFCollection model;

            if (id.HasValue && id.Value > 0)
            {
                model = CollectionService.GetCollection(id.Value);
                if (model == null)
                {
                    return(HttpNotFound("Collection was not found"));
                }
            }
            else
            {
                if (entityTypeId.HasValue)
                {
                    model = CollectionService.CreateCollection(entityTypeId.Value);
                }
                else
                {
                    List <CFEntityType> entityTypes = EntityTypeService.GetEntityTypes(CFEntityType.eTarget.Collections).ToList();
                    ViewBag.SelectEntityViewModel = new SelectEntityTypeViewModel()
                    {
                        EntityTypes = entityTypes
                    };

                    model = new CFCollection();
                }
            }

            return(View(model));
        }
예제 #2
0
 public void CreateCollection(string collectionName)
 {
     if (!(string.IsNullOrEmpty(collectionName) || CollectionService.DoesCollectionExist(collectionName)))
     {
         CollectionService.CreateCollection(collectionName);
     }
     else
     {
         throw new NameAlreadyExistsException();
     }
 }
예제 #3
0
        // GET: Manager/Collections/Edit/5
        public ActionResult Edit(int?id, int?entityTypeId)
        {
            SecurityService.CreateAccessContext();
            CFCollection model;

            if (id.HasValue && id.Value > 0)
            {
                model = CollectionService.GetCollection(id.Value);
                if (model == null)
                {
                    return(HttpNotFound("Collection was not found"));
                }

                //Sept 27 2019 -- set the READ ONLY
                if (!Catfish.Core.Contexts.AccessContext.current.IsAdmin)//not admin
                {
                    string accessMode = "";
                    foreach (CFAccessGroup ag in model.AccessGroups)
                    {
                        accessMode = ag.AccessDefinition.AccessModes.ToString();
                        if (accessMode == "Read")
                        {
                            ViewBag.ReadOnly = true;
                        }
                        else if (accessMode == "Write")
                        {
                            ViewBag.ReadOnly = false;
                            break;
                        }
                    }
                }
            }
            else
            {
                if (entityTypeId.HasValue)
                {
                    model = CollectionService.CreateCollection(entityTypeId.Value);
                }
                else
                {
                    List <CFEntityType> entityTypes = EntityTypeService.GetEntityTypes(CFEntityType.eTarget.Collections).ToList();
                    ViewBag.SelectEntityViewModel = new SelectEntityTypeViewModel()
                    {
                        EntityTypes = entityTypes
                    };

                    model = new CFCollection();
                }
            }

            return(View(model));
        }
예제 #4
0
        public CFCollection CreateCollection(CollectionService cs, int entityTypeId, string name, string description, bool store = false)
        {
            CFCollection c = cs.CreateCollection(entityTypeId);

            c.Name        = name;
            c.Description = description;


            if (store)
            {
                c = cs.UpdateStoredCollection(c);
            }

            return(c);
        }
예제 #5
0
        public void TestUpdateCollection()
        {
            DatabaseHelper    Dh = new DatabaseHelper(true);
            CollectionService Cs = new CollectionService(Dh.Db);
            int    entityTypeId  = Dh.Db.EntityTypes.Where(e => e.TargetTypes.Contains("Collection")).Select(e => e.Id).FirstOrDefault();
            string name          = "Test 2";
            string description   = "Description";
            string name2         = "Test 3";
            string description2  = "New Description";

            CFCollection c = CreateCollection(Cs, entityTypeId, name, description, true);

            Dh.Db.SaveChanges();

            c = Cs.GetCollection(c.Id);

            int    id      = c.Id;
            string content = c.Content;

            Assert.AreEqual(name, c.Name);
            Assert.AreEqual(description, c.Description);
            Assert.AreNotEqual(name2, c.Name);
            Assert.AreNotEqual(description2, c.Description);

            c             = Cs.CreateCollection(entityTypeId); // Since we are using an in memory database, we need to duplicate our collection.
            c.Id          = id;
            c.Name        = name2;
            c.Description = description2;
            Cs.UpdateStoredCollection(c);
            Dh.Db.SaveChanges();

            CFCollection c2 = Cs.GetCollection(id);

            Assert.AreNotEqual(name, c2.Name);
            Assert.AreNotEqual(description, c2.Description);
            Assert.AreEqual(name2, c2.Name);
            Assert.AreEqual(description2, c2.Description);
            Assert.AreEqual(id, c2.Id);
        }
예제 #6
0
        public ActionResult Edit(CFCollection model)
        {
            if (ModelState.IsValid)
            {
                CFCollection dbModel = CollectionService.UpdateStoredCollection(model);
                Db.SaveChanges(User.Identity);

                SuccessMessage(Catfish.Resources.Views.Collections.Edit.SaveSuccess);

                if (model.Id == 0)
                {
                    return(RedirectToAction("Edit", new { id = dbModel.Id }));
                }
                else
                {
                    return(View(dbModel));
                }
            }

            ErrorMessage(Catfish.Resources.Views.Collections.Edit.SaveInvalid);
            model = CollectionService.CreateCollection(model.EntityTypeId.Value);
            return(View(model));
        }
예제 #7
0
        public ActionResult Create(List <MainViewModel.CollectionViewModel> collecton)
        {
            var collectionResult = collection.CreateCollection(collecton);

            return(Json(collectionResult, JsonRequestBehavior.AllowGet));
        }