public async Task <IActionResult> PutAsyng(int id, [FromBody] SavePackageResource resource)
        {
            var package = _mapper.Map <SavePackageResource, Package>(resource);
            var result  = await _packageStateService.UpdateAsync(id, package);

            if (result == null)
            {
                return(BadRequest(result.Message));
            }

            var packageResource = _mapper.Map <Package, PackageResource>(result.Resource);

            return(Ok(packageResource));
        }
Пример #2
0
        public async Task <IActionResult> PostAsync([FromBody] SavePackageResource resource)
        {
            var package = mapper.Map <SavePackageResource, Package>(resource);
            var result  = await packageService.SaveAsync(package);

            if (!result.Success)
            {
                return(BadRequest(new ErrorResource(result.Message)));
            }

            var packageResource = mapper.Map <Package, PackageResource>(result.Package);

            return(Ok(packageResource));
        }
        public async Task <IActionResult> PostAsync([FromBody] SavePackageResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var package = _mapper.Map <SavePackageResource, Package>(resource);
            var result  = await _packageStateService.SaveAsync(package);

            if (!result.Sucess)
            {
                return(BadRequest(result.Message));
            }

            var packageResource = _mapper.Map <Package, PackageResource>(result.Resource);

            return(Ok(packageResource));
        }