public Version AddVersion(string name, IFormFile file)
        {
            string   ext      = file.FileName.Split(".").Last();
            Material material = _context.Materials.Include(p => p.Versions).FirstOrDefault(p => p.Name == name);
            Version  newVersion;

            if (material != null)
            {
                newVersion = new Version
                {
                    Material       = material,
                    Path           = _config.GetValue <string>("PathFiles") + material.Name + "_" + (material.Versions.Count() + 1) + $".{ext}",
                    Release        = material.Versions.Count() + 1,
                    Size           = file.Length,
                    UploadDateTime = DateTime.Now
                };
                using (var filestream = new FileStream(newVersion.Path, FileMode.Create))
                {
                    file.CopyTo(filestream);
                }
                _context.Versions.Add(newVersion);
                _context.SaveChanges();
                _backgroundJob.Enqueue(() => MailService.SendAsync($"New version of \"{material.Name}\" was added"));
                return(newVersion);
            }
            return(null);
        }
        public Version AddMaterial(Material material, IFormFile file)
        {
            string  ext = file.FileName.Split(".").Last();
            Version newVersion;

            if (_context.Materials.FirstOrDefault(p => p.Name == material.Name) == null)
            {
                newVersion = new Version
                {
                    Material       = material,
                    Path           = _config.GetValue <string>("PathFiles") + material.Name + "_1" + $".{ext}",
                    Release        = 1,
                    Size           = file.Length,
                    UploadDateTime = DateTime.Now
                };
                using (var filestream = new FileStream(newVersion.Path, FileMode.Create))
                {
                    file.CopyTo(filestream);
                }
                _context.Materials.Add(material);
                _context.Versions.Add(newVersion);
                _context.SaveChanges();
                _backgroundJob.Enqueue(() => MailService.SendAsync($"Material with name \"{material.Name}\" was created"));
                return(newVersion);
            }
            return(null);
        }
Esempio n. 3
0
        public Version AddVersion(string name, IFormFile file)
        {
            Material material = _repository.FindByName(name);
            Version  newVersion;

            if (material != null)
            {
                newVersion = new Version
                {
                    Material       = material,
                    Path           = _config.GetValue <string>("PathFiles") + material.Name + "_" + (material.Versions.Count() + 1) + '.' + file.FileName.Split('.')[1],
                    Release        = material.Versions.Count() + 1,
                    Size           = file.Length,
                    UploadDateTime = DateTime.Now
                };
                using (var filestream = new FileStream(newVersion.Path, FileMode.Create))
                {
                    file.CopyToAsync(filestream);
                }
                _repository.AddVersion(newVersion);
                _repository.AllSave();
                return(newVersion);
            }
            return(null);
        }
Esempio n. 4
0
        public Version AddMaterial(Material material, IFormFile file)
        {
            Version newVersion;

            if (_repository.FindByName(material.Name) == null)
            {
                newVersion = new Version
                {
                    Material       = material,
                    Path           = _config.GetValue <string>("PathFiles") + material.Name + "_1" + "." + material.Extension,
                    Release        = 1,
                    Size           = file.Length,
                    UploadDateTime = DateTime.Now
                };
                var filestream = new FileStream(newVersion.Path, FileMode.Create);

                file.CopyTo(filestream);
                _repository.AddMaterial(material);
                _repository.AddVersion(newVersion);
                _repository.AllSave();
                return(newVersion);
            }
            return(null);
        }
Esempio n. 5
0
 public void AddVersion(Version newVersion)
 {
     _context.Versions.Add(newVersion);
 }