Exemple #1
0
 public HttpResponseMessage GetProjectsbyUserName(string userName)
 {
     return(new HttpResponseMessage(HttpStatusCode.OK)
       {
           Content = new ObjectContent <List <Project> >(LogicWorkerToProject.GetProjectsbyUserName(userName), new JsonMediaTypeFormatter())
       });
 }
Exemple #2
0
      public HttpResponseMessage AddWorkerToProject([FromBody] WorkerToProject value, [FromUri] int userId)
      {
          if (ModelState.IsValid)
          {
              return((LogicWorkerToProject.AddWorkerToProject(value, userId)) ?
                     new HttpResponseMessage(HttpStatusCode.Created) :
                     new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new ObjectContent <String>("Can not add to DB", new JsonMediaTypeFormatter())
                });
          }
          ;

          List <string> ErrorList = new List <string>();

          foreach (var item in ModelState.Values)
          {
              foreach (var err in item.Errors)
              {
                  ErrorList.Add(err.ErrorMessage);
              }
          }

          return(new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter())
            });
      }
Exemple #3
0
      public HttpResponseMessage UpdateWorkerToProject([FromBody] WorkerToProject value)
      {
          if (ModelState.IsValid)
          {
              return((LogicWorkerToProject.UpdateWorkerToProject(value)) ?
                     new HttpResponseMessage(HttpStatusCode.OK) :
                     new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new ObjectContent <String>("Can not update in DB", new JsonMediaTypeFormatter())
                });
          }
          ;

          List <string> ErrorList = new List <string>();

          //if the code reached this part - the Project is not valid
          foreach (var item in ModelState.Values)
          {
              foreach (var err in item.Errors)
              {
                  ErrorList.Add(err.ErrorMessage);
              }
          }

          return(new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter())
            });
      }
Exemple #4
0
      public HttpResponseMessage GetWorkersHoursByTeam(int teamId)

      {
          return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ObjectContent <List <WorkerToProject> >(LogicWorkerToProject.GetWorkersHoursByTeam(teamId), new JsonMediaTypeFormatter())
            });
      }
Exemple #5
0
      public HttpResponseMessage GetAllWorkersToProject()

      {
          return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ObjectContent <List <WorkerToProject> >(LogicWorkerToProject.GetAllWorkersToProject(), new JsonMediaTypeFormatter())
            });
      }
Exemple #6
0
      public HttpResponseMessage GetWorkerToProjectByPidAndUid(int userId, int projectId)

      {
          var re      = Request;
          var headers = re.Headers;

          if (headers.Contains("Custom"))
          {
              string token = headers.GetValues("Custom").First();
          }

          //return null;

          return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ObjectContent <WorkerToProject>(LogicWorkerToProject.GetWorkersToProjectByProjectIdAndUserId(projectId, userId).FirstOrDefault(), new JsonMediaTypeFormatter())
            });
      }
        public HttpResponseMessage AddProject([FromBody] Project value, [FromUri] int userId)
        {
            if (ModelState.IsValid)
            {
                if (LogicProjects.AddProject(value, userId))
                {
                    List <User> users = LogicWorkerToProject.getUsersByTeamLeaderId(value.TeamLeaderId);

                    var id = LogicProjects.getProjectId(value.ProjectName);
                    value.ProjectId = id;
                    foreach (var item in users)
                    {
                        LogicWorkerToProject.AddWorkersByTeamLeaderId(id, item.UserId);
                    }

                    return(Request.CreateResponse(HttpStatusCode.Created, value));
                }

                else
                {
                    new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        Content = new ObjectContent <String>("Can not add to DB", new JsonMediaTypeFormatter())
                    };
                }
            }
            ;

            List <string> ErrorList = new List <string>();

            //if the code reached this part - the project is not valid
            foreach (var item in ModelState.Values)
            {
                foreach (var err in item.Errors)
                {
                    ErrorList.Add(err.ErrorMessage);
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter())
            });
        }