public IActionResult Put(int id, [FromBody] EmContact emContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != emContact.EmContactId)
            {
                return(BadRequest());
            }

            _context.Entry(emContact).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmContactExists(emContact.EmContactId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(new StatusCodeResult(StatusCodes.Status204NoContent));
        }
        public IActionResult Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            EmContact emContact = _context.EmContact.Single(c => c.EmContactId == id);

            if (emContact == null)
            {
                return(NotFound());
            }

            _context.EmContact.Remove(emContact);
            _context.SaveChanges();

            return(Ok(emContact));
        }
        public IActionResult Post([FromBody] EmContact emContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingEmContact = (from a in _context.EmContact
                                     where a.EmContactName == emContact.EmContactName &&
                                     a.CustomerId == emContact.CustomerId
                                     select a);

            //if emContact exists, it won't create another
            if (existingEmContact.Count <EmContact>() > 0)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }

            _context.EmContact.Add(emContact);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (EmContactExists(emContact.EmContactId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            return(Ok(emContact));
        }