Beispiel #1
0
        public JsonModels.CompleteProject GetProjectJson(Project project)
        {
            JsonModels.CompleteProject cp = new JsonModels.CompleteProject();
            if (project != null)
            {
                cp.coverPicture = project.coverPicture;
                cp.coverPictureThumbnail = project.coverPictureThumbnail;
                cp.description = project.description;
                cp.artifactOrder = project.projectElementOrder;
                cp.id = project.id;
                cp.title = project.name;
                cp.dateModified = project.dateModified.ToString();
                cp.props = GetProjectProps(project.id);
                if (project.projectElements == null)
                {
                    cp.artifacts = null;
                }
                else if (project.projectElementOrder != null)
                {
                    ReorderEngine re = new ReorderEngine();
                    List<int> IDS = re.stringOrderToList(project.projectElementOrder);
                    int[] ids = IDS.ToArray();

                    cp.artifacts = GetArtifacts(ids);
                    cp.artifactOrder = project.projectElementOrder;
                }
                return cp;
            }
            else
            {
                return null;
            }
        }
 public string UpdateProjectOrder(string order, string token)
 {
     Response.AddHeader("Access-Control-Allow-Origin", "*");
     if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))  //This is a preflight request
     {
         Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT");
         Response.AddHeader("Access-Control-Allow-Headers", "X-Requested-With");
         Response.AddHeader("Access-Control-Allow-Headers", "X-Request");
         Response.AddHeader("Access-Control-Allow-Headers", "X-File-Name");
         Response.AddHeader("Access-Control-Allow-Headers", "Content-Type");
         Response.AddHeader("Access-Control-Max-Age", "86400"); //caching this policy for 1 day
         return null;
     }
     else
     {
         try
         {
             int userId = authenticationEngine.authenticate(token);
             if (userId < 0)
             {
                 return AddErrorHeader("You are not authenticated, please log in!", 2);
             }
             User u = userManager.GetUser(userId);
             ReorderEngine re = new ReorderEngine();
             List<int> ListOrder = re.stringOrderToList(order);
             List<int> currentProjectIds = new List<int>();
             bool add = true;
             foreach (Project p in u.projects)
             {
                 currentProjectIds.Add(p.id);
             }
             foreach (int i in ListOrder)
             {
                 if (!currentProjectIds.Contains(i))
                 {
                     add = false;
                 }
             }
             if (add == false)
             {
                 //????????you cant do that
                 return AddErrorHeader("Update Failed.", 1);
             }
             else
             {
                 u.projectOrder = order;
                 u = userManager.UpdateUser(u);
             }
             return AddSuccessHeader("Order updated", true);
         }
         catch (Exception ex)
         {
             logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), ex.ToString());
             return AddErrorHeader("Something went wrong while updating the Project Order", 1);
         }
     }
 }
Beispiel #3
0
        public List<JsonModels.CompleteProject> GetCompleteProjects(int[] id, List<string> projectPrivacyPrivledge)
        {
            List<JsonModels.CompleteProject> projects = new List<JsonModels.CompleteProject>();
            ProjectAccessor pa = new ProjectAccessor();
            if (projectPrivacyPrivledge == null)
            {
                projectPrivacyPrivledge = new List<string>();
                projectPrivacyPrivledge.Add("public");
                projectPrivacyPrivledge.Add("network");
                projectPrivacyPrivledge.Add("private");
            }
            foreach (int i in id)
            {
                JsonModels.CompleteProject cp = new JsonModels.CompleteProject();
                ReorderEngine re = new ReorderEngine();
                Project p = pa.GetProject(i);
                if (p != null)
                {
                    if (p.isActive == true && (projectPrivacyPrivledge.Contains(p.privacy) || p.privacy == null))
                    {
                        cp.id = p.id;
                        if (p.name != null)
                        {
                            cp.title = p.name;
                        }
                        else
                        {
                            cp.title = null;
                        }
                        if (p.description != null)
                        {
                            cp.description = p.description;
                        }
                        else
                        {
                            cp.description = null;
                        }
                        cp.projectTags = GetProjectTags(p.id);

                        //we have to reset everyone's project order or when you add a new element this breaks - removes all old elements
                        List<int> peIds = new List<int>();
                        //just reset order if its null - duh!
                        if (p.projectElementOrder == null | p.projectElementOrder == "")
                        {
                            p = resetProjectElementOrder(p);
                            if (p.projectElementOrder != null)
                            {
                                List<int> IDS = re.stringOrderToList(p.projectElementOrder);
                                int[] ids = IDS.ToArray();
                                cp.artifactOrder = p.projectElementOrder;
                                cp.artifacts = GetArtifacts(ids);
                            }
                            else
                            {
                                cp.artifactOrder = null;
                                cp.artifacts = null;
                            }
                        }
                        else //projectElementOrder isn't null
                        {
                            List<int> IDS = re.stringOrderToList(p.projectElementOrder);
                            int[] ids = IDS.ToArray();
                            cp.artifacts = GetArtifacts(ids);
                            cp.artifactOrder = p.projectElementOrder;
                        }
                        if (p.coverPicture != null)
                        {
                            cp.coverPicture = p.coverPicture;
                        }
                        if (p.coverPictureThumbnail != null)
                        {
                            cp.coverPictureThumbnail = p.coverPictureThumbnail;
                        }
                        if (p.dateModified != null)
                        {
                            cp.dateModified = p.dateModified.ToString();
                        }
                        if (p.privacy != null)
                        {
                            cp.privacy = p.privacy;
                        }
                        cp.props = GetProjectProps(p.id);
                        projects.Add(cp);
                    }
                }
            }
            if (projects.Count != 0)
            {
                return projects;
            }
            else
            {
                return null;
            }
        }