public async Task <ActionResult <ServiceCM> > CreateService([FromForm] ServiceCM serviceModel) { //TODO: Implements AccountService.GetById(int id) does not exist, return BadRequest() //TODO: Implements ServiceTypeId.GetById(int id) does not exist, return BadRequest() //TODO: Implements GaleryId.GetById(int id) does not exist, return BadRequest() DateTime crtDate = DateTime.Now; DateTime updDate = DateTime.Now; string status = Constants.Status.ACTIVE; // Initialize gallery GalleryCM galleryCM = new GalleryCM(); galleryCM.Name = "Hình " + serviceModel.ServiceName.ToLower(); galleryCM.Description = "Hình " + serviceModel.ServiceName.ToLower();; // Add new gallery Gallery gallery = _mapper.Map <Gallery>(galleryCM); Gallery crtGallery = await _galleryService.AddAsync(gallery); await _galleryService.Save(); ImageCM imageCM = new ImageCM(); imageCM.Description = "Hình " + serviceModel.ServiceName; imageCM.GalleryId = crtGallery.Id; imageCM.ImageUrl = await _uploadFileService.UploadFile("123456798", serviceModel.File, "service", "service-detail"); Image image = _mapper.Map <Image>(imageCM); await _imageService.AddAsync(image); Service crtService = _mapper.Map <Service>(serviceModel); try { crtService.CreatedDate = crtDate; crtService.UpdatedDate = updDate; crtService.Status = status; crtService.AccountId = serviceModel.AccountId; crtService.ServiceTypeId = serviceModel.ServiceTypeId; crtService.GalleryId = crtGallery.Id; await _service.AddAsync(crtService); await _service.Save(); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction("GetServiceById", new { id = crtService.Id }, crtService)); }
public async Task <ActionResult <FeedBackCM> > CreateFeedback([FromForm] FeedBackCM feedbackModel) { //TODO: Implements BookingDetail.GetById(int id) does not exist, return BadRequest() //TODO: Implements GaleryId.GetById(int id) does not exist, return BadRequest() if (feedbackModel.File != null) { GalleryCM galleryCM = new GalleryCM(); galleryCM.Name = "Hình feedback cho dịch vụ trong đơn " + feedbackModel.BookingDetailId; galleryCM.Description = "Hình feedback cho dịch vụ trong đơn " + feedbackModel.BookingDetailId; Gallery gallery = _mapper.Map <Gallery>(galleryCM); Gallery crtGallery = await _galleryService.AddAsync(gallery); await _galleryService.Save(); feedbackModel.GalleryId = crtGallery.Id; ImageCM imageCM = new ImageCM(); imageCM.Description = "Hình feedback trong đơn " + feedbackModel.BookingDetailId; imageCM.GalleryId = crtGallery.Id; imageCM.ImageUrl = await _uploadFileService.UploadFile("123456798", feedbackModel.File, "service", "service-detail"); Image image = _mapper.Map <Image>(imageCM); await _imageService.AddAsync(image); } FeedBack crtFeedback = _mapper.Map <FeedBack>(feedbackModel); try { crtFeedback.CreateDate = DateTime.Now; await _service.AddAsync(crtFeedback); await _service.Save(); } catch (Exception e) { //return StatusCode(StatusCodes.Status500InternalServerError); NotFound(e); } return(CreatedAtAction("GetFeedBackById", new { id = crtFeedback.Id }, crtFeedback)); }
public async Task <ActionResult <ImageCM> > CreateImage([FromBody] ImageCM imageModel) { /*DateTime crtDate = DateTime.Now; * DateTime updDate = DateTime.Now;*/ Image crtImage = _mapper.Map <Image>(imageModel); try { /*crtService.CreatedDate = crtDate; * crtService.UpdatedDate = updDate;*/ await _service.AddAsync(crtImage); await _service.Save(); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction("GetImageById", new { id = crtImage.Id }, crtImage)); }