public async Task <JokeRecipient> Add(JokeRecipient jr) { var existing = _context.JokeRecipients.Where(r => r.Email == jr.Email).DefaultIfEmpty(null).First(); if (existing == null) { _context.JokeRecipients.Add(jr); await _context.SaveChangesAsync(); } return(jr); }
public async Task <ActionResult> Post([FromBody] JokeRecipient recipient) { if (AuthorizationUtils.Authorized(Request, _config) == false) { return(Unauthorized()); } if (recipient == null || String.IsNullOrEmpty(recipient.Name) || String.IsNullOrEmpty(recipient.Email)) { return(BadRequest()); } var j = await _data.Add(recipient); return(Ok()); }