public JsonResult AddUserTag(string value)
 {
     TagManager tm = new TagManager();
     string type;
     if (tm.GetAllSTagValues().Contains(value))
     {
         type = "s";
     }
     else
     {
         type = "f";
     }
     string result = tm.AddTag(value, type, userManager.GetUser(User.Identity.Name).id);
     if (result != null)
     {
         if (result == "Tag already added.")
         {
             return Json(new { tagStatus = "Tag already added" });
         }
         else
         {
             return Json(new { tagStatus = "Tag Added!" });
         }
     }
     else
     {
         return Json(new { Error = "Failed to add tag :(" });
     }
 }
예제 #2
0
        public string AddProjectTag(string value, int projectId, string token = null)
        {
            if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))  //This is a preflight request
            {
                return null;
            }
            else
            {
                try
                {
                    int userId;
                    if (token != null)
                    {
                        userId = authenticationEngine.authenticate(token);
                    }
                    else
                    {
                        return AddErrorHeader("An authentication token must be passed in", 2);
                    }

                    if (userId < 0)
                    {
                        return AddErrorHeader("User not authenticated, please log in!", 2);
                    }
                    User user = userManager.GetUser(userId);

                    Project project = projectManager.GetProject(projectId);
                    if (!projectManager.IsUserOwnerOfProject(projectId, user))
                    {
                        return AddErrorHeader("User not authorized to add a tag to this project", 3);
                    }
                    TagManager tm = new TagManager();
                    string type;
                    if (tm.GetAllSTagValues().Contains(value))
                    {
                        type = "s";
                    }
                    else
                    {
                        type = "f";
                    }
                    string result = tm.AddTag(value, type, projectId);
                    if (result != null)
                    {
                        if (result == "Tag already added.")
                        {
                            return AddErrorHeader("This tag already exists", 1);
                        }
                        else
                        {
                            activityManager.AddActivity(user.id, "Project Tag", "Added", project.id);
                            return AddSuccessHeader("Tag Added Successfully" , true);
                        }
                    }
                    else
                    {
                        return AddErrorHeader("Tag could not be added to Project", 1);
                    }
                }
                catch (Exception ex)
                {
                    logAccessor.CreateLog(DateTime.Now,"ProjectController - AddProjectTag", ex.StackTrace);
                    return AddErrorHeader("Something went wrong while adding this Project Tag", 1);
                }
            }
        }