public async Task <IActionResult> Post([FromBody] BicycleRequestViewModel viewModel) { try { if (ModelState.IsValid) { var response = await BicycleService.InsertAsync(new ORM.Bicycle { BicyleCondition = viewModel.BicyleCondition, CreatedOn = DateTime.Now, Model = viewModel.Model }); return(StatusCode(201, new ResponseViewModel <BicycleResponseViewModel> { data = MapResponse(response), message = "Bicycle created", statusCode = 201 })); } return(BadRequest(new ResponseViewModel <bool> { data = false, message = "all fields are required", statusCode = 400 })); }catch (Exception ex) { return(EasyServerError(ex)); } }
public async Task <IActionResult> Put([FromBody] BicycleRequestViewModel viewModel) { try { if (ModelState.IsValid) { //var bike = await BicycleService.GetByIdAsync(viewModel.Id); var response = await BicycleService.UpdateAsync(new ORM.Bicycle { BicyleCondition = viewModel.BicyleCondition, Model = viewModel.Model, UpdatedOn = DateTime.Now, CreatedOn = viewModel.CreatedOn, Id = viewModel.Id }); return(Ok(new ResponseViewModel <BicycleResponseViewModel> { data = MapResponse(response), message = "record upadated", statusCode = 200 })); } return(BadRequest(new ResponseViewModel <bool> { data = false, message = "All feilds are required", statusCode = 400 })); } catch (Exception ex) { return(EasyServerError(ex)); } }
public async Task <IActionResult> Put([FromBody] BicycleRequestViewModel viewModel) { try { if (ModelState.IsValid) { var response = await new NetWorkCalls <ResponseViewModel <BicycleResponseViewModel> >().PUT(Configuration.BicycleMicroservice.Put, JsonConvert.SerializeObject(viewModel)); return(Ok(response)); } return(BadRequest(new ResponseViewModel <bool> { data = false, message = "all fields are required", statusCode = 400 })); } catch (Exception ex) { return(EasyServerError(ex)); } }