Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        private ResponsePostRental ResponseMessage(StatusPost codeMessage)
        {
            ResponsePostRental response = new ResponsePostRental();

            switch (codeMessage)
            {
            case StatusPost.Pending:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Approved:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Cancel:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Block:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Setp4:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Delete:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Error:
                response.MessageCode = (int)StatusPost.Error;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Error);
                break;

            case StatusPost.Susscess:
                response.MessageCode = (int)StatusPost.Susscess;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Susscess);
                break;

            default:
                response.MessageCode = 0;
                response.Message     = "Không tìm được, dữ liệu phù hợp";
                break;
            }
            return(response);
        }
Beispiel #3
0
        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));
            }
        }