예제 #1
0
        public virtual JsonResult Upload(long id, AwbFileType type, HttpPostedFileBase file)
        {
            var bytes = file.GetBytes();

            var fileId = _files.Add(id, type, file.FileName, bytes);

            AddFileUploadEvent(id, TypesMapping[type], file.FileName, bytes);

            return(Json(new { id = fileId }));
        }
예제 #2
0
		public virtual JsonResult Files(long id, AwbFileType type)
		{
			var names = _files.GetNames(id, type);

			ViewBag.AwbId = id;

			return Json(names.Select(x => new
			{
				id = x.Id,
				name = x.Name
			}),
				JsonRequestBehavior.AllowGet);
		}
예제 #3
0
        public virtual JsonResult Files(long id, AwbFileType type)
        {
            var names = _files.GetNames(id, type);

            ViewBag.AwbId = id;

            return(Json(names.Select(x => new
            {
                id = x.Id,
                name = x.Name
            }),
                        JsonRequestBehavior.AllowGet));
        }
예제 #4
0
        public ReadOnlyCollection <FileInfo> GetNames(long awbId, AwbFileType type)
        {
            var idsTable   = TableParameters.GeIdsTable("AwbIds", new[] { awbId });
            var parameters = new TableParameters(new { TypeId = type }, idsTable);

            var infos = _executor.Array <dynamic>("[dbo].[AwbFile_GetNames]", parameters)
                        .Select(x => new FileInfo
            {
                Id   = x.Id,
                Name = x.Name
            })
                        .ToArray();

            return(new ReadOnlyCollection <FileInfo>(infos));
        }
예제 #5
0
		public ReadOnlyCollection<FileInfo> GetNames(long awbId, AwbFileType type)
		{
			var idsTable = TableParameters.GeIdsTable("AwbIds", new[] { awbId });
			var parameters = new TableParameters(new { TypeId = type }, idsTable);

			var infos = _executor.Array<dynamic>("[dbo].[AwbFile_GetNames]", parameters)
				.Select(x => new FileInfo
				{
					Id = x.Id,
					Name = x.Name
				})
				.ToArray();

			return new ReadOnlyCollection<FileInfo>(infos);
		}
예제 #6
0
        public void Test_GetNames()
        {
            var bytes = _fixture.Create <byte[]>();
            var name  = _fixture.CreateMany <string>(2).OrderBy(x => x).ToArray();
            const AwbFileType fileType = (AwbFileType)(-1);

            var id1 = _repository.Add(TestConstants.TestAwbId, fileType, name[0], bytes);
            var id2 = _repository.Add(TestConstants.TestAwbId, fileType, name[1], bytes);

            var names = _repository.GetNames(TestConstants.TestAwbId, fileType);

            names.Should().HaveCount(2);
            names[0].Id.ShouldBeEquivalentTo(id1);
            names[1].Id.ShouldBeEquivalentTo(id2);
            names[0].Name.ShouldBeEquivalentTo(name[0]);
            names[1].Name.ShouldBeEquivalentTo(name[1]);
        }
예제 #7
0
        private static void Insert(SqlConnection filesDb, long id,
                                   AwbFileType fileType, string fileName, byte[] fileData)
        {
            if (string.IsNullOrEmpty(fileName) || fileData == null)
            {
                return;
            }

            filesDb.Execute(@"
					INSERT [dbo].[AwbFile] ([AwbId], [Data], [Name], [TypeId])
					VALUES (@AwbId, @Data, @Name, @TypeId)"                    , new
            {
                AwbId  = id,
                TypeId = fileType,
                Name   = fileName,
                Data   = fileData
            });
        }
예제 #8
0
파일: Program.cs 프로젝트: UHgEHEP/test
		private static void Insert(SqlConnection filesDb, long id,
			AwbFileType fileType, string fileName, byte[] fileData)
		{
			if(string.IsNullOrEmpty(fileName) || fileData == null)
			{
				return;
			}

			filesDb.Execute(@"
					INSERT [dbo].[AwbFile] ([AwbId], [Data], [Name], [TypeId])
					VALUES (@AwbId, @Data, @Name, @TypeId)", new
				{
					AwbId = id,
					TypeId = fileType,
					Name = fileName,
					Data = fileData
				});
		}
예제 #9
0
		public ReadOnlyDictionary<long, ReadOnlyCollection<FileInfo>> GetInfo(long[] awbIds, AwbFileType type)
		{
			var idsTable = TableParameters.GeIdsTable("AwbIds", awbIds);
			var parameters = new TableParameters(new { TypeId = type }, idsTable);

			var dictionary = _executor.Array<dynamic>("[dbo].[AwbFile_GetNames]", parameters)
				.GroupBy(x => (long)x.AwbId)
				.ToDictionary(a => a.Key,
					a =>
					{
						var infos = a.Select(x => new FileInfo
						{
							Id = x.Id,
							Name = x.Name
						}).ToArray();

						return new ReadOnlyCollection<FileInfo>(infos);
					});

			return new ReadOnlyDictionary<long, ReadOnlyCollection<FileInfo>>(dictionary);
		}
예제 #10
0
        private FileHolder GetFileHolder(long awbId, AwbFileType awbFileType)
        {
            var name = GetNames(awbId, awbFileType).FirstOrDefault();

            return(name != null?Get(name.Id) : null);
        }
예제 #11
0
		public long Add(long awbId, AwbFileType type, string name, byte[] data)
		{
			return _executor.Query<long>("[dbo].[AwbFile_Add]", new { awbId, TypeId = type, name, data });
		}
예제 #12
0
		private FileHolder GetFileHolder(long awbId, AwbFileType awbFileType)
		{
			var name = GetNames(awbId, awbFileType).FirstOrDefault();

			return name != null ? Get(name.Id) : null;
		}
예제 #13
0
		private ReadOnlyDictionary<long, ReadOnlyCollection<FileInfo>> GetFileInfo(long[] ids, AwbFileType type)
		{
			return _files.GetInfo(ids, type);
		}
예제 #14
0
		public virtual JsonResult Upload(long id, AwbFileType type, HttpPostedFileBase file)
		{
			var bytes = file.GetBytes();

			var fileId = _files.Add(id, type, file.FileName, bytes);

			AddFileUploadEvent(id, TypesMapping[type], file.FileName, bytes);

			return Json(new { id = fileId });
		}
예제 #15
0
        public ReadOnlyDictionary <long, ReadOnlyCollection <FileInfo> > GetInfo(long[] awbIds, AwbFileType type)
        {
            var idsTable   = TableParameters.GeIdsTable("AwbIds", awbIds);
            var parameters = new TableParameters(new { TypeId = type }, idsTable);

            var dictionary = _executor.Array <dynamic>("[dbo].[AwbFile_GetNames]", parameters)
                             .GroupBy(x => (long)x.AwbId)
                             .ToDictionary(a => a.Key,
                                           a =>
            {
                var infos = a.Select(x => new FileInfo
                {
                    Id   = x.Id,
                    Name = x.Name
                }).ToArray();

                return(new ReadOnlyCollection <FileInfo>(infos));
            });

            return(new ReadOnlyDictionary <long, ReadOnlyCollection <FileInfo> >(dictionary));
        }
예제 #16
0
 public long Add(long awbId, AwbFileType type, string name, byte[] data)
 {
     return(_executor.Query <long>("[dbo].[AwbFile_Add]", new { awbId, TypeId = type, name, data }));
 }
예제 #17
0
 private ReadOnlyDictionary <long, ReadOnlyCollection <FileInfo> > GetFileInfo(long[] ids, AwbFileType type)
 {
     return(_files.GetInfo(ids, type));
 }