public async Task <IActionResult> CreateProperty(PropertyToRegisterDto propertyToRegisterDto)
        {
            var propertyToCreate = _mapper.Map <CompaniesPropertyInquiry>(propertyToRegisterDto);

            _repo.Add(propertyToCreate);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to save the new property"));
        }
예제 #2
0
        public async Task <IActionResult> CreateConfirmation(ConfirmationToCreateDto confirmationToCreateDto)
        {
            var confirmationToCreate = _mapper.Map <Confirmation>(confirmationToCreateDto);

            _repo.Add(confirmationToCreate);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to save the new confirmation"));
        }
        public async Task <IActionResult> UploadFile([FromForm] UploadedFileToRegister uploadedFileToRegister)
        {
            var file       = uploadedFileToRegister.File;
            var folderName = Path.Combine("Files", uploadedFileToRegister.CompanyId.ToString());

            Directory.CreateDirectory(folderName);
            var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);

            uploadedFileToRegister.FileUploadDate = DateTime.Now;

            if (file != null)
            {
                var fileName       = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                int indexOfLastDot = fileName.LastIndexOf(".");
                var uniqueName     = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +
                                     DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString();
                fileName = fileName.Insert(indexOfLastDot, "_" + uniqueName);
                var fullPath = Path.Combine(pathToSave, fileName);
                var dbPath   = Path.Combine(folderName, fileName);
                uploadedFileToRegister.FileName = fileName;

                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    file.CopyTo(stream);
                }

                var fileToAdd = _mapper.Map <FileUpload>(uploadedFileToRegister);

                fileToAdd.FilePath = dbPath;

                _repo.Add(fileToAdd);

                if (await _repo.SaveAll())
                {
                    return(Ok(new { dbPath }));
                }
            }



            return(BadRequest("Failed to add new file"));
        }
 public bool Add(AssetRegistration entity)
 {
     return(repository.Add(entity));
 }