public async Task <ActionResult> PutAsync(int id, [FromBody] AppNotificatonsTemplate item) { if (!ModelState.IsValid || id != item.id) { return(BadRequest()); } try { var exist = await service.GetByIdAsync(id); if (exist != null) { var result = await service.UpdateAsync(item); return(result ? Ok(item) : StatusCode(500, new Response() { Status = false, Description = "Error updating record" })); } else { return(BadRequest()); } } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, new Response() { Status = false, Description = "System error" })); } }
public async Task <ActionResult> PostAsync([FromBody] AppNotificatonsTemplate item) { if (!ModelState.IsValid) { return(BadRequest()); } try { var exist = await service.GetAsync(x => x.emailsubject == item.emailsubject); if (exist != null) { return(Conflict(new Response() { Status = false, Description = "Duplicate record" })); } var result = await service.AddAsync(item); if (result) { var newitem = await service.GetAsync(x => x.emailsubject == item.emailsubject); return(StatusCode(201, newitem)); } else { return(BadRequest()); } } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, new Response() { Status = false, Description = "System error" })); } }