Пример #1
0
 public Employee GetByFn(string term)
 {
     using (angulardbEntities entities = new angulardbEntities())
     {
         return(entities.Employees.FirstOrDefault(e => e.FirstName == term));
     }
 }
Пример #2
0
        //[HttpGet]
        //[Route("api/Employees/{id}/{term}")]

        //public IEnumerable<Employee> GetAll()
        //{
        //    using (angulardbEntities entities = new angulardbEntities())
        //    {
        //        return entities.Employees.ToList();
        //    }
        //}


        public Employee GetById(int id)
        {
            using (angulardbEntities entities = new angulardbEntities())
            {
                return(entities.Employees.FirstOrDefault(e => e.Id == id));
            }
        }
Пример #3
0
 public void Delete(int id)
 {
     using (angulardbEntities entities = new angulardbEntities())
     {
         entities.Employees.Remove(entities.Employees.FirstOrDefault(e => e.Id == id));
         entities.SaveChanges();
     }
 }
Пример #4
0
        public void Put(int id, [FromBody] Employee employee)
        {
            using (angulardbEntities entities = new angulardbEntities())
            {
                var entity = entities.Employees.FirstOrDefault(e => e.Id == id);

                entity.FirstName = employee.FirstName;
                entity.LastName  = employee.LastName;

                entities.SaveChanges();
            }
        }
Пример #5
0
        public void Post([FromBody] Employee employee)
        {
            try
            {
                using (angulardbEntities entities = new angulardbEntities())
                {
                    entities.Employees.Add(employee);
                    entities.SaveChanges();

                    //var message = Request.CreateResponse(HttpStatusCode.Created, employee);
                    //message.Headers.Location = new Uri(Request.RequestUri + employee.Id.ToString());
                    //return message;
                }
            }
            catch (Exception ex)
            {
                Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
            }
        }