public virtual async Task <JsonResult> Add(Address model) { if (!ModelState.IsValid) { return(Json(new { IsSuccessful = false, Message = ModelState.GetModelError() })); } return(Json(await _addressSrv.AddAsync(model))); }
public async Task <IActionResult> AddAsync(Address address) { var result = await _addressService.AddAsync(address); if (result.Success) { return(Ok(JsonConvert.SerializeObject(result.Message))); } return(BadRequest(JsonConvert.SerializeObject(result.Message))); }
public async Task <ActionResult <AddressDto> > PostAsync(AddressDto body) { var result = await _addressService.AddAsync(UserId, body); if (result == null) { return(BadRequest()); } return(Created($"{HttpContext.Request.Path}/{result.Id}", result)); }
// // Summary: // /// Method responsible for initializing the schema. /// // // Parameters: // addressService: // The addressService param. // public AddressMutationType(IAddressService addressService) { Name = "AddressMutation"; Description = "Address Mutation Type"; FieldAsync <AddressType>( name: "createAddress", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <AddressInputType> > { Name = "data" } ), resolve: async context => { AddressCommand data = context.GetArgument <AddressCommand>("data"); Address result = await addressService.AddAsync(data); if (addressService.ValidationResult().IsValid is true) { return(result); } context.Errors.AddRange(addressService.ValidationResult().Errors.Select(x => new ExecutionError(x.ErrorMessage))); return(null); } ); FieldAsync <BooleanGraphType>( name: "removeAddress", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" } ), resolve: async context => { Guid id = context.GetArgument <Guid>("id"); await addressService.RemoveAsync(id); if (addressService.ValidationResult().IsValid is true) { return(true); } context.Errors.AddRange(addressService.ValidationResult().Errors.Select(x => new ExecutionError(x.ErrorMessage))); return(null); } ); }
public async Task <ActionResult <AddressCM> > CreateAddress([FromBody] AddressCM model) { Address crtAddress = _mapper.Map <Address>(model); try { await _service.AddAsync(crtAddress); await _service.Save(); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction("GetAddressById", new { id = crtAddress.Id }, crtAddress)); }
public async Task <IActionResult> Create([FromBody] AddressCommand command) { if (command is null) { return(BadRequest()); } Address address = await _addressService.AddAsync(command); if (address is null) { return(BadRequest(_addressService.ValidationResult() .Errors .Select(x => new ValidationResult() { PropertyName = x.PropertyName, ErrorMessage = x.ErrorMessage }))); } return(Ok(_mapper.Map <Address, AddressResult>(address))); }
public async Task <IActionResult> GetAllAdresses([FromBody] AddressModel model) { SuccessResponseModel result = await _addressService.AddAsync(User.Identity.Name, model); return(Ok(result)); }
public async Task <IActionResult> Save(AddressDto addressDto) { var addressSave = await _addressService.AddAsync(_mapper.Map <Address>(addressDto)); return(Created(string.Empty, _mapper.Map <AddressDto>(addressSave))); }