Q:

Миграция клиент-серверного приложения с Web Api MVC4 на Web Api Core

Пытаюсь реализовать клиент серверное академическое приложение. Пытаюсь мигрировать на современный фреймворк и наступил на грабли...
Серверная часть:
Модель:
    public int Id { get; set; }
    public string Name { get; set; }
    public string LastName { get; set; }
    public string Department { get; set; }
    public string ImagePath { get; set; }
    public DateTimeOffset DateAndTime { get; set; }

Контекст:
  public class EmployeeContext : DbContext
  {
    public DbSet<Employee> Employee { get; set; }

    public EmployeeContext(DbContextOptions<EmployeeContext> options)
        : base(options)
    { }

    public EmployeeContext()
    {
    }
  }

Репозиторий:
  public interface IEmployeeRepository
  {
    Employee Add(Employee employee);
    Employee Get(int id);
    IQueryable<Employee> GetAll();
    void Remove(int id);
    bool Update(Employee employee);
  }

Реализация(по поводу id не ругайтесь, пока для теста сделал):
public class EmployeeRepository
{
    //private List<Employee> _employee = new List<Employee>();
    EmployeeContext db = new EmployeeContext();

    private int _nextId = 1;

    public IQueryable<Employee> GetAll()
    {
        EmployeeContext empContext = new EmployeeContext();

        try
        {
            return empContext.Employee.AsQueryable();
        }
        catch (Exception err)
        {
            throw new Exception(err.Message);
        }

    }

    public Employee Add(Employee employee)
    {
        using (EmployeeContext empContext = new EmployeeContext())
        {
            try
            {
                employee.Id = _nextId++;
                empContext.Employee.Add(employee);
                empContext.SaveChanges();
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
            return employee;
        }

    }

    public Employee Get(int id)
    {

        using (EmployeeContext empContext = new EmployeeContext())
        {
            return empContext.Employee.SingleOrDefault(c => c.Id == id);
        }
    }

    public void Remove(int id)
    {
        using (EmployeeContext empContext = new EmployeeContext())
        {
            try
            {
                Employee employeeToRemove = new Employee
                {
                    Id = id
                };
                empContext.Employee.Attach(employeeToRemove);
                empContext.Employee.Remove(employeeToRemove);
                empContext.SaveChanges();
            }
            catch (Exception err)
            {
                throw new Exception(string.Format("Сотрудника не существует или запись удалена!" + err.Message));
            }

            //OnChanged.Invoke(null, new EventArgs());

        }

    }

    public bool Update(Employee employee)
    {
        using (EmployeeContext empContext = new EmployeeContext())
        {
            var index = empContext.Employee.FirstOrDefault(c => c.Id == employee.Id);
            if (index != null)
            {
                return false;
            }
            empContext.Employee.Remove(index);
            empContext.Employee.Add(employee);
            return true;
        }
    }
}

Пространства имен в контроллере:
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Web;
   using System.Threading.Tasks;
   using Microsoft.AspNetCore.Http;
   using Microsoft.AspNetCore.Mvc;
   using WebApiCoreTest.Model;
   using System.Net.Http;
   using System.Net;
   using System.Net.Http.Formatting;

Контроллер:
[Route("api/[controller]")]
public class EmployeeController : Controller
{

    static readonly IEmployeeRepository repository = new 
    EmployeeRepository();

    public EmployeeController() { }

    public IEnumerable<Employee> GetAllEmployee()
    {
        return repository.GetAll();
    }
    public Employee GetEmployee(int id)
    {
        Employee item = repository.Get(id);
        if (item == null)
        {
            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
        }
        return item;
    }
    public IEnumerable<Employee> GetEmployeeByName(string name)
    {
        return repository.GetAll().Where(
            p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase));
    }

    public HttpResponseMessage PostEmployee(Employee item)
    {
        item = repository.Add(item);
        var response = Request.CreateResponse<Employee>(HttpStatusCode.Created, item);
        string uri = Url.Link("DefaultApi", new { id = item.Id });
        response.Headers.Location = new Uri(uri);
        return response;
    }
    //public void PutEmployee(int id, Employee employee)
    //{
    //    employee.Id = id;
    //    if (!repository.Update(employee))
    //    {
    //        throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
    //    }
    //}
    public HttpResponseMessage DeleteEmployee(int id)
    {
        repository.Remove(id);
        return new HttpResponseMessage(HttpStatusCode.NoContent);
    }
}

В контроллере ругается на HttpResponseException и CreateResponse

Как можно это побороть?
Клиент написан на WFP, этот метод прибайндин к DataGrid для получения списка Employee:
private void BindEmployeeList()
    {
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri("http://localhost:55872");

        // Add an Accept header for JSON format.
        client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

        HttpResponseMessage response = client.GetAsync("api/[controller]").Result;

        if (response.IsSuccessStatusCode)
        {
            var employees = response.Content.ReadAsAsync<IEnumerable<Employee>>().GetAwaiter().GetResult();
            grdEmployee.ItemsSource = employees;
        }
        else
        {
            MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase);
        }

    }

A:

Задача решена благодаря хорошему посту на хабре! Я лишь сделал под себя и переписал свой предыдущий код. Я надеюсь что он поможет новичкам, которые столкнулись с такой же проблемой как я.

Модель:
public class Person
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string LastName { get; set; }
    public string Department { get; set; }
    public DateTimeOffset DateTime { get; set; }
    public string Path { get; set; }
}

Хранилище:
 public interface IPersonRepository
{
    Person Add(Person person);
    Person Get(Guid id);
    IEnumerable<Person> GetAll();
    void Remove(Guid id);
    bool Update(Person person);
}

Реализация хранилища:
public class PersonRepository : IPersonRepository
{
    private readonly PersonContext _personContext;

    public PersonRepository(PersonContext personContext)
    {
        _personContext = personContext;
    }

    public Person Add(Person person)
    {
        try
        {
             person.Id = Guid.NewGuid();
            _personContext.Persons.Add(person);
            _personContext.SaveChanges();
        }
        catch (Exception err)
        {
            throw new Exception(err.Message);
        }
        return person;
    }

    public Person Get(Guid id)
    {
        return _personContext.Persons.SingleOrDefault(c => c.Id == id);
    }

    public IEnumerable<Person> GetAll()
    {
        try
        {
            return _personContext.Persons.AsQueryable();
        }
        catch (Exception err)
        {
            throw new Exception(err.Message);
        }
    }

    public void Remove(Guid id)
    {

        try
        {
            Person employeeToRemove = new Person { Id = id };
            _personContext.Persons.Attach(employeeToRemove);
            _personContext.Persons.Remove(employeeToRemove);
            _personContext.SaveChanges();
        }
        catch (Exception err)
        {
            throw new Exception(string.Format("Сотрудника не существует или запись удалена!" + err.Message));
        }

    }

    public bool Update(Person person)
    {
        throw new NotImplementedException();
    }
}

Контроллер:
 [Route("api/[controller]")]
public class PersonController : Controller
{

    public IPersonRepository Person { get; set; }

    public PersonController(IPersonRepository person)
    {
        Person = person;
    }

    public IEnumerable<Person> GetAll()
    {
        return Person.GetAll();
    }

    [HttpGet("{id}", Name = "GetTodo")]
    public IActionResult GetById(Guid id)
    {
        var item = Person.Get(id);
        if (item == null)
        {
            return NotFound();
        }
        return new ObjectResult(item);
    }

    [HttpPost]
    public IActionResult Create([FromBody] Person person)
    {
        if (person == null)
        {
            return BadRequest();
        }
        Person.Add(person);
        return CreatedAtRoute("GetTodo", new { id = person.Id }, person);
    }

    [HttpPut("{id}")]
    public IActionResult Update(string id, [FromBody] Person person)
    {
        // Do something
    }

    [HttpPatch("{id}")]
    public IActionResult Update([FromBody] Person item, string id)
    {
        // Do something
    }

    [HttpDelete("{id}")]
    public IActionResult Delete(Guid id)
    {
        var todo = Person.Get(id);
        if (todo == null)
        {
            return NotFound();
        }

        Person.Remove(id);
        return new NoContentResult();
    }

}

И код клиента без класса диалоговых окон, для примера только добавление:
String urlAddress = ConfigurationManager.AppSettings["serverUriString"];

    public MainWindow()
    {
        InitializeComponent();
        BindTodoList();
    }

    private void BindTodoList()
    {
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri(urlAddress);

        // Add an Accept header for JSON format.
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        using (HttpResponseMessage response = client.GetAsync("api/person/").GetAwaiter().GetResult())
        {
            if (response.IsSuccessStatusCode)
            {
                var employees = response.Content.ReadAsAsync<IEnumerable<Person>>().GetAwaiter().GetResult();
                grdEmployee.ItemsSource = employees;
            }
            else
            {
                MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase);
            }
        }

    }

    private void btnAdd_Click(object sender, RoutedEventArgs e)
    {
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri(urlAddress);

        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        var todo = new Person();

        todo.Name = txtName.Text;
        todo.LastName = txtLastName.Text;
        todo.Department = txtDepartment.Text;
        todo.Path = txtPath.Text;
        todo.DateTime = DateTime.Now;

        using (var response = client.PostAsJsonAsync("api/person/", todo).GetAwaiter().GetResult())
        {
            if (response.IsSuccessStatusCode)
            {
                MessageBox.Show("Employee Added");
                txtName.Text = "";
                txtLastName.Text = "";
                txtDepartment.Text = "";
                txtPath.Text = "";
                BindTodoList();
            }
            else
            {
                MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase);
            }
        }

    }

    private void btnShowAll_Click(object sender, RoutedEventArgs e)
    {
        BindTodoList();

    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        BindTodoList();
    }

