示例#1
0
        public IActionResult Schedule(TaxScheduleRequest request)
        {
            var tax = _taxScheduleMapper.ToTax(request);

            if (tax == null)
            {
                return(BadRequest());
            }

            var isScheduled = _taxService.ScheduleTax(request.Municipality, tax);

            return(isScheduled ? (IActionResult)Ok() : BadRequest());
        }
        public Tax ToTax(TaxScheduleRequest request)
        {
            var taxType = ToTaxType(request.TaxType);
            if(taxType == null)
            {
                return null;
            }

            return new Tax {
                Rate = request.Rate,
                TaxType = taxType.Value,
                From = request.From
            };
        }
        public ActionResult ReadAll(Guid municipalityId, [FromQuery] TaxScheduleRequest request)
        {
            var municipalityExist = this.service.IsMunicipalityExist(municipalityId);

            if (!municipalityExist)
            {
                return(this.NotFound($"Municipality doesn't exists or has no schedules"));
            }

            if (!this.service.HasFields(request.Fields))
            {
                return(this.BadRequest());
            }

            var items = this.service.ReadWithParameters(request);

            return(this.Ok(items));
        }
        public IEnumerable <ExpandoObject> ReadWithParameters(TaxScheduleRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var entities = this.repository.ReadAll();

            if (!string.IsNullOrWhiteSpace(request.Id))
            {
                var id = Guid.Parse(request.Id);
                entities = entities.Where(m => m.Id == id);
            }

            if (!string.IsNullOrWhiteSpace(request.ScheduleType))
            {
                Enum.TryParse(request.ScheduleType, out ScheduleType e);
                entities = entities.Where(m => m.ScheduleType == e);
            }

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                var searchQuery = request.SearchQuery.Trim();
                entities = entities.Where(x => x.Id.ToString().Contains(searchQuery) ||
                                          x.ScheduleType.ToString().Contains(searchQuery));
            }

            if (!string.IsNullOrWhiteSpace(request.OrderBy))
            {
                var orderByArray = request.OrderBy.Split(',');

                foreach (var req in orderByArray)
                {
                    var trimmedRequest = req.Trim();
                    entities = entities.OrderByProp(trimmedRequest);
                }
            }

            var page = PagingHelper <TaxSchedule> .MakePage(entities, request.PageNumber, request.PageSize);

            return(this.mapper.Map <IEnumerable <TaxScheduleDto> >(source: page)
                   .ReturnFieldsOnly(request.Fields));
        }