public IActionResult Add([FromBody] AddResourceViewModel model)
        {
            var resource = resourceService.Detail(model.Content);

            if (resource != null)
            {
                return(APIResult.失败.SetMessage(string.Format(LocalResource.AlreadyExists, model.Content)));
            }

            var check = CheckParent(model.ParentId);

            if (check.Code != APIResult.OK)
            {
                return(check);
            }

            resource = resourceService.Add(
                new M_Resource
            {
                Authorize = model.Authorize,
                Name      = model.Name,
                Content   = model.Content,
                Type      = model.Type,
                ParentId  = model.ParentId,
                Sort      = model.Sort
            });

            return(APIResult.成功.SetData("id", resource.Id));
        }
Beispiel #2
0
        /// <summary>
        /// 添加一条新的资源记录
        /// </summary>
        /// <param name="r">资源实体类型</param>
        /// <returns></returns>
        public void Add(ResourceEntity r)
        {
            ResourceService rs = new ResourceService();

            rs.Add(r.ItemId, r.ItemSerialNum, r.FileName,
                   r.FolderName,
                   r.FileSize,
                   r.ServerFileName,
                   r.Caption,
                   r.StartDate,
                   r.EndDate,
                   r.uploadDate,
                   r.shotDate,
                   r.Keyword,
                   r.Description,
                   r.updateDate,
                   r.userId,
                   r.Status,
                   r.ResourceType,
                   r.Author,
                   r.HasCopyright
                   );

            //同时更新索引
            string[] SNs = new string[] { r.ItemSerialNum };
            ResourceIndex.updateIndex(SNs);
        }
Beispiel #3
0
        public async Task <IActionResult> Add([FromBody] NewResource model)
        {
            var resource = await _svc.Add(model);

            Audit(AuditId.ResourceState);
            return(Json(resource));
        }
        public void Update_updates_item_from_database()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>()
                          .UseInMemoryDatabase(databaseName: "Update_updates_item_from_database")
                          .Options;

            using (var context = new DatabaseContext(options))
            {
                var resource = new Resource
                {
                    Weight        = 10,
                    MaximumWeight = 15,
                    SchedulingId  = 10
                };

                var service = new ResourceService(context, new ResourceRepository(context));
                service.Add(resource);
                Assert.Single(context.Set <Resource>().ToList());
                Assert.Equal(10, context.Set <Resource>().Single().Weight);

                resource.Weight = 13;
                service.Update(1, resource);
                Assert.Equal(13, context.Set <Resource>().Single().Weight);
            }
        }
        public void Delete_deletes_from_database()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_deletes_from_database")
                          .Options;

            using (var context = new DatabaseContext(options))
            {
                var resource = new Resource
                {
                    Weight        = 10,
                    MaximumWeight = 15,
                    SchedulingId  = 10
                };

                var service = new ResourceService(context, new ResourceRepository(context));
                service.Add(resource);
                Assert.Single(context.Set <Resource>().ToList());

                var insertedResource = service.GetAll().First();

                service.Delete(insertedResource.Id);
                Assert.Empty(context.Set <Resource>().ToList());
            }
        }
        public void Add_writes_to_database()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            using (var context = new DatabaseContext(options))
            {
                var resource = new Resource
                {
                    Weight        = 10,
                    MaximumWeight = 15,
                    SchedulingId  = 10
                };

                var service = new ResourceService(context, new ResourceRepository(context));
                service.Add(resource);
            }

            using (var context = new DatabaseContext(options))
            {
                Assert.Single(context.Set <Resource>().ToList());

                Assert.Equal(1, context.Set <Resource>().Single().Id);
            }
        }
Beispiel #7
0
 public AnimationDataEntry(AnimationService animService, IDrawing drawing,
                           string name, IProjectFile file)
 {
     Name           = name;
     _drawing       = drawing;
     _file          = file;
     _animationData = animService.GetAnimationData(file);
     _directory     = Path.GetDirectoryName(file.FullPath);
     _textures      = new ResourceService <Guid, ISurface>(OnLoad, OnDispose);
     foreach (var k in _animationData.Textures)
     {
         _textures.Add(k.Id);
     }
 }
Beispiel #8
0
        /// <summary>
        /// 添加一条新的资源记录
        /// </summary>
        /// <param name="r">资源实体类型</param>
        /// <returns></returns>
        public void Add(ResourceEntity r)
        {
            ResourceService rs = new ResourceService();
            rs.Add(r.ItemId, r.ItemSerialNum, r.FileName,
                r.FolderName,
                r.FileSize,
                r.ServerFileName, 
                r.Caption,
                r.StartDate,
                r.EndDate,
                r.uploadDate,
                r.shotDate,
                r.Keyword,
                r.Description,
                r.updateDate,
                r.userId,
                r.Status,
                r.ResourceType,
                r.Author,
                r.HasCopyright
                );

            //同时更新索引
            string[] SNs = new string[] { r.ItemSerialNum };
            ResourceIndex.updateIndex(SNs);
        }
Beispiel #9
0
 public Resource Add(Resource resource)
 {
     return(_resourceService.Add(resource));
 }