예제 #1
0
        public async Task <IActionResult> CreateServiceType([FromBody] SaveServiceTypeResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var st = _mapper.Map <SaveServiceTypeResource, ServiceType>(resource);

            _repository.Add(st);

            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map <ServiceType, SaveServiceTypeResource>(st);

            return(Ok(result));
        }
예제 #2
0
        public async Task <IActionResult> UpdateServiceType(int id, [FromBody] SaveServiceTypeResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var st = await _repository.GetServiceTypeAsync(id);

            if (st == null)
            {
                return(NotFound());
            }

            st = _mapper.Map(resource, st);

            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map <ServiceType, SaveServiceTypeResource>(st);

            return(Ok(result));
        }