public IHttpActionResult GetJobServiceMapping(int id) { JobServiceMappingBindingModel jobServiceMappingBindingModel = new JobServiceMappingBindingModel(); JobServiceMappingModel jobServiceMappingModel = new JobServiceMappingModel(); AutoMapper.Mapper.Map(jobServiceMappingBindingModel, jobServiceMappingModel); jobServiceMappingModel = jobServiceMappingService.GetJobServiceMappingById(id); AutoMapper.Mapper.Map(jobServiceMappingModel, jobServiceMappingBindingModel); return Ok(jobServiceMappingBindingModel); }
public IHttpActionResult PostJobServiceMapping(JobServiceMappingBindingModel model) { JobServiceMappingModel jobServiceMappingModel = new JobServiceMappingModel(); JobServicePictureMappingModel jobServicePictureMappingModel = new JobServicePictureMappingModel(); if (!ModelState.IsValid) { return BadRequest(ModelState); } var root = HttpContext.Current.Server.MapPath(Utility.Constants.BASE_FILE_UPLOAD_PATH); Directory.CreateDirectory(root); //if (ProfileImage != null) //{ // var filename = Guid.NewGuid() + ".jpg"; // ProfileImage.SaveAs(Path.Combine(root, Utility.Constants.JOB_SERVICE_IMAGES_PATH, filename)); // jobServicePictureMappingModel.ImagePath = filename; //} //else //{ // jobServicePictureMappingModel.ImagePath = ""; //} AutoMapper.Mapper.Map(model, jobServiceMappingModel); jobServiceMappingModel = jobServiceMappingService.SaveJobServiceMapping(jobServiceMappingModel); AutoMapper.Mapper.Map(jobServiceMappingModel, model); jobServicePictureMappingModel.JobServiceMappingId = model.JobServiceMappingId; string fileName; if (HttpContext.Current.Request.Files != null) { for (var i = 0; i < HttpContext.Current.Request.Files.Count; i++) { var file = HttpContext.Current.Request.Files[i]; fileName = file.FileName; file.SaveAs(Path.Combine(root, Utility.Constants.JOB_SERVICE_IMAGES_PATH, fileName)); jobServicePictureMappingModel.ImagePath = fileName; jobServicePictureMappingModel = jobServicePictruesMappingService.SaveJobServicePictureMapping(jobServicePictureMappingModel); } } return Ok(model); }
public IHttpActionResult PutJobServiceMapping(JobServiceMappingBindingModel model) { try { JobServiceMappingModel jobServiceMappingModel = new JobServiceMappingModel(); if (!ModelState.IsValid) { return BadRequest(ModelState); } AutoMapper.Mapper.Map(model, jobServiceMappingModel); jobServiceMappingModel = jobServiceMappingService.UpadteJobServiceMapping(jobServiceMappingModel); AutoMapper.Mapper.Map(jobServiceMappingModel, model); return Ok(model); } catch(Exception ex) { return BadRequest(ex.Message); } }