public async Task <IActionResult> Post([FromForm] JobForTableDTO JobDTO) { if (ModelState.IsValid) { await _jobService.Add(JobDTO); return(Ok()); } return(BadRequest()); }
public async Task <IActionResult> Update([FromForm] JobForTableDTO jobDTO, [FromRoute] int id) { if (ModelState.IsValid) { await _jobService.Update(jobDTO, id); return(Ok()); } return(BadRequest()); }
public async Task Update(JobForTableDTO jobDTO, int id) { var UserId = Convert.ToInt32(_context.HttpContext.User.Claims.Where(x => x.Type == "UserId").First().Value); IFormFile file = jobDTO.Image; string fullPath = null; var imageId = 0; Job job = await _jobRepository.GetJobByID(id); if (file != null) { string folderName = "Upload"; string webRootPath = _hostingEnvironment.WebRootPath; if (string.IsNullOrWhiteSpace(webRootPath)) { webRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); fullPath = Path.Combine(newPath, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } } imageId = _serviceImage.GetIdInsertedImage(fullPath); job.ImageId = imageId; } job.UserId = UserId; job.PostDate = DateTime.Now; job.CategoryId = jobDTO.CategoryId; job.CityId = jobDTO.CityId; job.Title = jobDTO.Title; job.Salary = jobDTO.Salary; job.TypeJobId = jobDTO.TypeJobId; job.EndDate = jobDTO.FinishedOn; job.Contact = jobDTO.Contact; await _jobRepository.Update(job); }