public IActionResult AddNewMaterial() { var file = Request.Form.Files[0]; var detailsDecode = JObject.Parse(Request.Form["materialDetails"]); var folderName = Path.Combine("Resources", "Materials"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); var fullPath = Path.Combine(pathToSave, file.FileName); if (file.Length > 0) { var dbPath = Path.Combine(folderName, file.FileName); using (var stream = System.IO.File.Create(fullPath)) { file.CopyTo(stream); } string materialName = detailsDecode["name"].ToString(); string materialInformations = detailsDecode["informations"].ToString(); string materialChemicalComposition = detailsDecode["chemicalComposition"].ToString(); var material = new CreateMaterialRequest { Name = materialName, MaterialPhoto = dbPath, AdditionalInformations = materialInformations, ChemicalComposition = materialChemicalComposition }; materialRepository.Create(material.returnMaterial()); } return(Ok(new ApiResponse("Added succesfully!"))); }
public async Task <GetMaterialResponse> AddMaterial(Guid serviceRequestId, CreateMaterialRequest dto) { var serviceRequest = await _unitOfWork.ServiceRequests.Get(serviceRequestId); // validate if (serviceRequest is null) { throw new KeyNotFoundException("Service request does not exist."); } if (serviceRequest.Status != Status.InProgress) { throw new AppException("This service is not in progress."); } var newMaterial = _mapper.Map <Material>(dto); newMaterial.ServiceRequestId = serviceRequestId; _unitOfWork.Materials.Add(newMaterial); _unitOfWork.Commit(); return(_mapper.Map <GetMaterialResponse>(newMaterial)); }
public MaterialModel CreateMaterial([FromBody] CreateMaterialRequest request) { return(_manager.CreateMaterial(request.ArticleID, request.FileCode).ToSerial()); }
public async Task <ActionResult <GetMaterialResponse> > AddMaterial(Guid serviceRequestId, [FromBody] CreateMaterialRequest dto) { return(Ok(await _serviceRequestService.AddMaterial(serviceRequestId, dto))); }