Example #1
0
        public FileModel CreateMaterial(NewMaterialDTO data)
        {
            string        name     = data.FileName;
            string        category = data.Category;
            ulong         size     = (ulong)data.fileBlob.Length;
            int           version  = 1;
            MaterialModel material = new MaterialModel();

            material.Name     = name;
            material.Category = category;
            if (_context.Materials.Count() > 0)
            {
                material.Id = _context.Materials.Max(f => f.Id) + 1;
            }
            else
            {
                material.Id = 1;
            }
            // materials.Add(material);
            _context.Add(material);
            FileModel file = new FileModel();

            file.MaterialId = material.Id;
            file.Version    = version;
            file.Size       = size;
            file.Id         = _context.Files.Count() > 0 ? _context.Files.Max(f => f.Id) + 1 : 1;
            file.Path       = _fileService.UploadFile(material, file, data.fileBlob);
            file.UploadTime = DateTime.Now;
            _context.Add(file);
            _context.SaveChanges();
            return(file);
        }
Example #2
0
        public void ChangeMaterialCategory(int materialId, string category)
        {
            MaterialModel material = _context.Materials.Where(m => m.Id == materialId).FirstOrDefault();

            material.Category = category;
            _context.SaveChanges();
        }
Example #3
0
        public string UploadFile(MaterialModel material, FileModel fileModel, byte[] file)
        {
            string path = $"Files\\{material.Id}-{fileModel.Id}";

            File.WriteAllBytes(path, file);

            /*using (var fileStream = new FileStream(path, FileMode.Create))
             * {
             *  file.CopyToAsync(fileStream);
             * }*/
            return(path);
        }
Example #4
0
        public FileModel UpdateMaterial(UpdateMaterialDTO data)
        {
            MaterialModel material = _context.Materials.Where(m => m.Id == data.MaterialId).FirstOrDefault();
            FileModel     file     = new FileModel();

            file.MaterialId = material.Id;
            file.Version    = _context.Files.Where(f => f.MaterialId == material.Id).Max(f => f.Version) + 1;
            file.Size       = (ulong)data.fileBlob.Length;
            file.Id         = _context.Files.Count() > 0 ? _context.Files.Max(f => f.Id) + 1 : 1;
            file.Path       = _fileService.UploadFile(material, file, data.fileBlob);
            file.UploadTime = DateTime.Now;
            _context.Add(file);
            _context.SaveChanges();
            return(file);
        }