Exemple #1
0
        public Material AddMaterial(Material material, IFormFile file)
        {
            Version newVersion;

            if (material != null)
            {
                newVersion = new Version
                {
                    Material       = material,
                    UploadTime     = DateTime.Now,
                    Size           = file.Length,
                    VersionCounter = 1
                };
                string path = _config.GetValue <String>("FilesPath:Type:ProjectDirectory") + material.Name + "_v1";
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    file.CopyToAsync(fileStream);
                    fileStream.Flush();
                }
                _materialRepository.AddMaterial(material);
                _versionRepository.AddVersion(newVersion);
                _materialRepository.Save();
                return(material);
            }
            return(null);
        }
        public ActionResult <MaterialDto> CreateMaterialForPerson(Guid personId, MaterialForCreationDto material)
        {
            if (!_materialRepository.PersonExists(personId))
            {
                return(NotFound());
            }

            var materialEntity = _mapper.Map <Material>(material);

            _materialRepository.AddMaterial(personId, materialEntity);
            _materialRepository.Save();

            var materialToReturn = _mapper.Map <MaterialDto>(materialEntity);

            return(CreatedAtRoute("GetMaterialForPerson",
                                  new { personId = personId, materialId = materialToReturn.Id },
                                  materialToReturn));
        }
Exemple #3
0
 public MaterialMutation(IMaterialRepository repository)
 {
     FieldAsync <MaterialQueryType>(
         "addMaterial",
         arguments: new QueryArguments(new QueryArgument <NonNullGraphType <MaterialCreateViewModel> >
     {
         Name = "material"
     }),
         resolve: async context =>
     {
         var material = context.GetArgument <Material>("material");
         return(await context.TryAsyncResolve(async _ => await repository.AddMaterial(material)));
     }
         );
 }
        public async Task <IActionResult> PostMaterial([FromBody] KeyValuePairResource materialResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var material = mapper.Map <KeyValuePairResource, Material>(materialResource);

            if (material == null)
            {
                return(BadRequest("Bad Material"));
            }
            materialRepository.AddMaterial(material);
            await unitOfWork.CompleteAsync();

            return(Ok(mapper.Map <Material, KeyValuePairResource>(material)));
        }
Exemple #5
0
        public async Task <IActionResult> PostMaterial(MaterialDTO material)
        {
            // auto map this converstion somehow, constructor with other repositories?
            var classification = material.FlyClassificationId != null ? await _flyContext.FlyClassifications.FindAsync(material.FlyClassificationId) : null;

            var materialCategory = await _flyContext.MaterialCategories.FindAsync(material.MaterialCategoryId);

            var newMaterial = new Material()
            {
                Name = material.Name, FlyClassification = classification, MaterialCategory = materialCategory
            };

            _materialsRepo.AddMaterial(newMaterial);
            await _materialsRepo.SaveChangesAsync();

            await _materialsRepo.GetMaterialAsync(newMaterial.Id);

            return(CreatedAtAction("GetMaterial", new { id = newMaterial.Id }, newMaterial));
        }
Exemple #6
0
        /// <summary>
        /// <see cref="IMaterialRepository.AddMaterial(Material)"/>
        /// </summary>
        public bool AddMaterial(Material material, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (material == null)
            {
                errorMessage = "Material can`t be null";
                return(false);
            }

            if (string.IsNullOrWhiteSpace(material.Name))
            {
                errorMessage = "Material name can`t be empty";
                return(false);
            }

            if (material.PricePerGramm < 0)
            {
                errorMessage = "Material price can`t be negative";
                return(false);
            }

            if (material.CreatedBy == Guid.Empty)
            {
                errorMessage = "Material creator can`t be emprty";
                return(false);
            }

            Material materialFromRepository = _rMaterialRepository.GetAllMaterials()
                                              .Where(m => m.Name == material.Name && m.CreatedBy == material.CreatedBy)
                                              .FirstOrDefault();

            if (materialFromRepository != null)
            {
                errorMessage = "The same material already exist";
                return(false);
            }

            return(_rMaterialRepository.AddMaterial(material));
        }