コード例 #1
0
 public void Delete(int id)
 {
     using (angulardbEntities entities = new angulardbEntities())
     {
         entities.Employees.Remove(entities.Employees.FirstOrDefault(e => e.Id == id));
         entities.SaveChanges();
     }
 }
コード例 #2
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();
            }
        }
コード例 #3
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);
            }
        }