public async Task <IActionResult> Create(CategoryCityResource resource)
        {
            var response = new SingleModelResponse <CategoryCityResource>();

            if (resource == null)
            {
                response.DidError     = true;
                response.ErrorMessage = ResponseMessageConstants.NotFound;
                return(response.ToHttpResponse());
            }

            try
            {
                var entity = new CategoryCity();
                _mapper.Map(resource, entity);

                var entityAdded = await _cateBookingRepository.AddAsync(entity);

                response.Model   = _mapper.Map(entityAdded, resource);
                response.Message = ResponseMessageConstants.Success;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Update(int id, CategoryCityResource resource)
        {
            var response = new SingleModelResponse <CategoryCityResource>();

            if (resource == null)
            {
                response.DidError     = true;
                response.ErrorMessage = ResponseMessageConstants.NotFound;
                return(response.ToHttpResponse());
            }
            try
            {
                var entity = await _cateBookingRepository.FindAsync(x => x.Id == id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = ResponseMessageConstants.NotFound;
                    return(response.ToHttpResponse());
                }

                entity.CityName = resource.CityName;
                entity.CityCode = resource.CityCode;
                entity.Position = resource.Position;
                entity.IsActive = resource.IsActive;

                await _cateBookingRepository.UpdateAsync(entity);

                response.Model   = _mapper.Map(entity, resource);
                response.Message = ResponseMessageConstants.Success;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
                _logger.LogInformation(ex.Message);
                _logger.LogTrace(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <CategoryCityResource>();

            try
            {
                var entity = await _cateBookingRepository.DeleteAsync(id);

                var resource = new CategoryCityResource();
                response.Model   = _mapper.Map(entity, resource);
                response.Message = ResponseMessageConstants.Delete;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
                _logger.LogError(ex.InnerException.ToString());
            }

            return(response.ToHttpResponse());
        }
示例#4
0
 public async Task <IActionResult> Create([FromBody] CategoryCityResource resource)
 {
     return(await _service.Create(resource));
 }
示例#5
0
 public async Task <IActionResult> Update(int id, [FromBody] CategoryCityResource resource)
 {
     return(await _service.Update(id, resource));
 }