public async Task <IActionResult> Get(string id) { if (id == null) { return(BadRequest()); } var notify = new Notification.Model.Notification(); await Task.Run(() => { notify = _context.Notifications.FirstOrDefault(c => c.Id == id); }); return(Ok(notify)); }
public async Task <IActionResult> Post([FromBody] Notification.Model.Notification notify) { if (notify == null) { return(BadRequest()); } notify.Id = Guid.NewGuid().ToString(); await Task.Run(() => { _context.Notifications.AddAsync(notify); _context.SaveChanges(); }); return(Ok(notify.Id)); }
public async Task <IActionResult> Put([FromBody] Notification.Model.Notification notify) { if (notify == null) { return(BadRequest()); } var notification = new Notification.Model.Notification(); await Task.Run(() => { notification = _context.Notifications.Find(notify.Id); _context.Entry(notification).CurrentValues.SetValues(notify); _context.SaveChanges(); }); return(Ok($"Update record {notify.Id} done!")); }
public async Task <IActionResult> SendMail([FromBody] Notification.Model.Notification notification) { if (notification == null) { return(BadRequest()); } notification.Id = Guid.NewGuid().ToString(); await Task.Run(() => { _context.Notifications.AddAsync(notification); _context.SaveChanges(); }); await _smtpService.SendAsync(notification.Receiver, notification.Body, notification.Title); return(Ok()); }