コード例 #1
0
        public async Task <IActionResult> Post([FromBody] Agency model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Agency newAgency = new Agency
                    {
                        Name    = model.Name,
                        Phone   = model.Phone,
                        Email   = model.Email,
                        Address = model.Address
                    };

                    var savedAgency = service.Add(newAgency);
                    if (savedAgency != null)
                    {
                        return(Created($"/api/agency/{newAgency.Id}", newAgency));
                    }
                    else
                    {
                        return(BadRequest(ModelState));
                    }
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to save new partner: {ex}");
                return(BadRequest($"Failed to save new partner beacuse of exception, end user better not see this one :)"));
            }
        }
コード例 #2
0
        public IActionResult AddAgency([FromBody] AgencyCreate model)
        {
            var result = _agencyService.Add(model.ToDataModel());

            return(ProcessResult(result,
                                 a => Ok(new BaseResponse <Agency>(a.ToDTOModel()))
                                 ));
        }
コード例 #3
0
 public IActionResult Post([FromBody] Agency model)
 {
     return(Ok(
                _agencyService.Add(model)
                ));
 }