public async Task <bool> Update(ContatoPost contatoPost) { var success = false; var existingcontatoPost = Get(contatoPost.Id); if (existingcontatoPost != null) { existingcontatoPost.Nome = contatoPost.Nome; existingcontatoPost.Canal = contatoPost.Canal; existingcontatoPost.Valor = contatoPost.Valor; existingcontatoPost.Obs = contatoPost.Obs; existingcontatoPost.DataAlteracao = contatoPost.DataAlteracao; _databaseContext.ContatoPosts.Attach(existingcontatoPost); var numberOfItemsUpdated = await _databaseContext.SaveChangesAsync(); if (numberOfItemsUpdated == 1) { success = true; } } return(success); }
public static bool IsValid(this ContatoPost contatoPost, out IEnumerable <string> errors) { var validator = new ContatoPostValidator(); var validationResult = validator.Validate(contatoPost); errors = AggregateErrors(validationResult); return(validationResult.IsValid); }
public async Task <IActionResult> Update([FromBody] ContatoPost contatoPost) { if (contatoPost.IsValid(out IEnumerable <string> errors)) { var result = await _contatoPostService.Update(contatoPost); return(Ok(result)); } else { return(BadRequest(errors)); } }
public async Task <bool> Create(ContatoPost contatoPost) { var success = false; _databaseContext.ContatoPosts.Add(contatoPost); var numberOfItemsCreated = await _databaseContext.SaveChangesAsync(); if (numberOfItemsCreated == 1) { success = true; } return(success); }
public void CreateLote() { for (int a = 0; a < 50; a++) { ContatoPost contatoPost = new ContatoPost { Id = a.ToString(), Nome = "Nome" + a.ToString(), Canal = "Canal" + a.ToString(), Valor = "valor" + a.ToString(), Obs = "Obs" + a.ToString() }; _contatoPostService.Create(contatoPost); } }
public async Task <IActionResult> Create([FromBody] ContatoPost contatoPost) { if (contatoPost.IsValid(out IEnumerable <string> errors)) { var result = await _contatoPostService.Create(contatoPost); return(CreatedAtAction( nameof(GetAllByUserAccountId), new { id = result.Nome }, result)); } else { return(BadRequest(errors)); } }
public async Task <ContatoPost> Update(ContatoPost contatoPost) { contatoPost.DataAlteracao = DateTime.UtcNow; var success = await _repository.Update(contatoPost); if (success) { return(contatoPost); } else { return(null); } }