public IActionResult Post([FromBody] MyModelViewModel viewModel) { try { if (viewModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MyModel item = Mapper.Map <MyModel>(viewModel); _exampleRepository.Add(item); int save = _exampleRepository.Save(); if (save > 0) { return(CreatedAtRoute("GetSingle", new { controller = "MyModel", id = item.Id }, item)); } return(BadRequest()); } catch (Exception exception) { //Do something with the exception return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public async Task <Guid> Handle(CreateExample request, CancellationToken cancellationToken) { Guid id = Guid.NewGuid(); Example example = Example.Create(id, request.Content); await _exampleRepository.Add(example); await _eventProcessor.Process(example.Events); return(id); }
public bool CreateExampleModel(ExampleModel exampleModel) { try { _repository.Add(exampleModel); _repository.SaveChanges(); } catch { return(false); } return(true); }
public async Task <int> CreateExample(CreateExampleModel createExampleModel) { var example = new Example() { CreatedDate = DateTime.Now, Name = createExampleModel.Name, Age = createExampleModel.Age }; var createdExample = await exampleRepository.Add(example); return(createdExample.Id); }
public void Add(Example example) { try { example.GenerateId(); validation.Validate(example); exampleRepository.Add(example); } catch (Exception ex) { throw ex; } }
public async Task <Example> AddExample(Example request) { var newExample = Example.ExampleFactory.AddExample(request.Descricao); if (!await IsValidAsync(newExample)) { return(await Task.FromResult(request)); } _exampleRepository.Add(newExample); if (await Commit()) { return(await Task.FromResult(newExample)); } return(request); }
public void Post([FromBody] Example model) { _exampleRepository.Add(model); }