Пример #1
0
        public HttpResponseMessage put(int TaskId, string EmployeeId, TASKEMPLOYEES taskemployees)
        {
            try
            {
                using (TaskEmployeesEntities entities = new TaskEmployeesEntities())
                {
                    var entity = entities.TASKEMPLOYEES.FirstOrDefault(e => e.TaskId == TaskId && e.EmployeeId == EmployeeId);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "TaskEmployees doesnt exist"));
                    }
                    else
                    {
                        entity.EmployeeId = taskemployees.EmployeeId;
                        entity.TaskId     = TaskId;
                        entities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Пример #2
0
 public HttpResponseMessage post([FromBody] TASKEMPLOYEES taskemployees)
 {
     try
     {
         using (TaskEmployeesEntities entities = new TaskEmployeesEntities())
         {
             entities.TASKEMPLOYEES.Add(taskemployees);
             entities.SaveChanges();
             HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Created, taskemployees);
             message.Headers.Location = new Uri(Request.RequestUri + "?TaskId=" + taskemployees.TaskId.ToString() + "&EmployeeId=" + taskemployees.EmployeeId);
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }