public IActionResult Put(int id, [FromBody] PostModel model) { ResponsePostRental response = new ResponsePostRental(); StatusPost statusPost = (StatusPost)model.Status; if (model == null && model?.Status == null) { response = ResponseMessage(statusPost); return(BadRequest(response)); } try { RentalPost updatePost = new RentalPost(); RentalPost rentalPost = _rentalPostService.GetById(id); switch (statusPost) { case StatusPost.Pending: rentalPost.Status = (byte)StatusPost.Pending; _rentalPostService.UppdatePost(rentalPost); break; case StatusPost.Approved: rentalPost.Status = (byte)StatusPost.Approved; _rentalPostService.UppdatePost(rentalPost); break; case StatusPost.Cancel: rentalPost.Status = (byte)StatusPost.Cancel; _rentalPostService.UppdatePost(rentalPost); break; case StatusPost.Setp4: _rentalPostService.DeletePictureForPost(rentalPost.Id); _rentalPostService.DeleteUtilitiesOfPost(rentalPost.Id); _rentalPostService.InsertPicturesForPost(model.PictureIds, rentalPost.Id); _rentalPostService.InsertUtilitiesForPost(model.UtilitiesIds, rentalPost.Id); updatePost = model.ConvertSetp(rentalPost); _rentalPostService.UppdatePost(updatePost); break; case StatusPost.Delete: rentalPost.Status = (byte)StatusPost.Delete; _rentalPostService.UppdatePost(rentalPost); break; default: break; } response = ResponseMessage(StatusPost.Susscess); return(Ok(response)); } catch (Exception ex) { response = ResponseMessage(StatusPost.Susscess); _logger.Error("Post PostRentalController", ex); return(BadRequest(response)); } }
public IActionResult Post([FromBody] PostModel model) { ResponsePostRental response = new ResponsePostRental(); try { RentalPost entity = new RentalPost(); entity = model.ConvertSetp(entity); var provincial = _territoriesServices.GetById(entity.ProvincialId); var Ward = _territoriesServices.GetById(entity.WardId); var District = _territoriesServices.GetById(entity.DistrictId); string addressDeatail = string.Format("{0} , {1} , {2} , {3}", entity.AddressDetail, provincial == null ? "": provincial.Name, District == null ? "": District.Name, Ward == null ? "": Ward.Name); entity.AddressDetail = addressDeatail; var lester = _lesterServices.GetByUserId(AccessControl.User.Id); if (lester == null) { response = ResponseMessage(StatusPost.Error); return(BadRequest(response)); } entity.CreateBy = lester.Id; entity.LesterId = lester.Id; _rentalPostService.InsertPost(entity); if (model.PictureIds != null) { _rentalPostService.InsertPicturesForPost(model.PictureIds, entity.Id); } if (model.UtilitiesIds != null) { _rentalPostService.InsertUtilitiesForPost(model.UtilitiesIds, entity.Id); } response = ResponseMessage(StatusPost.Susscess); return(Ok(response)); } catch (Exception ex) { response = ResponseMessage(StatusPost.Error); _logger.Error("Post PostRentalController", ex); return(BadRequest(response)); } }