public JToken GetByKey(string url, JsonModels model, string key, string value)
 {
     using (var webClient = new WebClient())
     {
         return(webClient.DownloadString(url).ConvertToJtoken(model, key, value));
     }
 }
 public IEnumerable <JToken> GetAllById(string url, JsonModels model, string key, string id)
 {
     using (var webClient = new WebClient())
     {
         return(webClient.DownloadString(url).ConvertToList(model, key, id));
     }
 }
Exemple #3
0
        public ViewResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(ViewBag.NameSortParm) && sortOrder != "name_asc" ? "name_asc" : "name_desc";
            ViewBag.DateSortParm = String.IsNullOrEmpty(ViewBag.DateSortParm) && sortOrder != "date_desc" ? "date_desc" : "date_asc";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            using (var webClient = new System.Net.WebClient())
            {
                var        json = webClient.DownloadString(url);
                JsonModels root = JsonConvert.DeserializeObject <JsonModels>(json);

                if (!String.IsNullOrEmpty(searchString))
                {
                    root.Articles = root.Articles.Where(s => s.Author.Contains(searchString) ||
                                                        s.Description.Contains(searchString) ||
                                                        s.Title.Contains(searchString));
                }

                switch (sortOrder)
                {
                case "name_desc":
                    root.Articles = root.Articles.OrderByDescending(s => s.Title).ToList();
                    break;

                case "name_asc":
                    root.Articles = root.Articles.OrderBy(s => s.Title).ToList();
                    break;

                case "date_desc":
                    root.Articles = root.Articles.OrderByDescending(s => s.PublishedAt).ToList();
                    break;

                case "date_asc":
                    root.Articles = root.Articles.OrderBy(s => s.PublishedAt).ToList();
                    break;
                }

                int pageSize   = 3;
                int pageNumber = (page ?? 1);
                return(View(root.Articles.ToPagedList(pageNumber, pageSize)));
            }
        }
        public async System.Threading.Tasks.Task <ActionResult> Delete(string tag)
        {
            HttpClient client = new HttpClient();

            var values = new Dictionary <string, string>
            {
                { "Tag", tag }
            };

            var content = new FormUrlEncodedContent(values);

            string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";

            var response = await client.PostAsync(baseUrl + "api/Relations/RemovePact", content);

            return(View("Pacts", JsonConvert.DeserializeObject <List <Relation> >(JsonModels.GetJson((Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/") + "api/relations/byset/" + Startup.Storage.Reset))));
        }
        public JsonModels.Network UpdateNetworkModel(JsonModels.Network networkJson)
        {
            try
            {
                if (networkJson != null)
                {
                    Network originalNetwork = networkAccessor.GetNetwork(networkJson.id);
                    if (originalNetwork != null)
                    {
                        originalNetwork.description = networkJson.description;
                        originalNetwork.name = networkJson.name;
                        originalNetwork.privacy = networkJson.privacy;

                        Network returnNetwork = networkAccessor.UpdateNetworkInformation(originalNetwork);
                        return (GetNetworkJson(returnNetwork));
                    }
                    else
                    {
                        //network id not found in database
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, "Network Manager - CreateSubNetwork", ex.StackTrace);
                return null;
            }
        }
 public ActionResult AddPact(Relation relation)
 {
     if (relation.ValidateRelation())
     {
         Startup.Storage.Relations.Add(relation);
         Startup.Storage.newlyAddedRelations = true;
         if (Request.UrlReferrer.AbsolutePath == "/relations/New")
         {
             return(View("Pacts", JsonConvert.DeserializeObject <List <Relation> >(JsonModels.GetJson((Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/") + "api/relations/byset/" + Startup.Storage.Reset))));
         }
         else
         {
             return(Json(true, JsonRequestBehavior.DenyGet));
         }
     }
     if (Request.UrlReferrer.AbsolutePath == "/relations/New")
     {
         return(View("Pacts", JsonConvert.DeserializeObject <List <Relation> >(JsonModels.GetJson((Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/") + "api/relations/byset/" + Startup.Storage.Reset))));
     }
     else
     {
         return(Json(false, JsonRequestBehavior.DenyGet));
     }
 }
 public ActionResult Pacts()
 {
     return(View(JsonConvert.DeserializeObject <List <Relation> >(JsonModels.GetJson((Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/") + "api/relations/byset/" + Startup.Storage.Reset))));
 }
Exemple #8
0
 public static JToken ConvertToJtoken(this string mockResult, JsonModels model, string key, string value)
 {
     return(JObject.Parse(mockResult)[model.ToString()]?.FirstOrDefault(x => x[key].ToString().Equals(value)));
 }
Exemple #9
0
 public static IEnumerable <JToken> ConvertToList(this string mockResult, JsonModels model, string key, string value)
 {
     return(JObject.Parse(mockResult)[model.ToString()]?.Where(x => x[key].ToString().Equals(value)));
 }
Exemple #10
0
        public string UpdateProfileModel(JsonModels.ProfileInformation profile, string token = null)
        {
            if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))
            {
                return null;
            }
            try
            {
                int authUserId = -1;
                if (token != null)
                {
                    authUserId = authenticationEngine.authenticate(token);
                }
                else
                {
                    return AddErrorHeader("An authentication token must be passed in");
                }
                if (authUserId < 0)
                {
                    return AddErrorHeader("You are not authenticated, please log in!");
                }
                JsonModels.ProfileInformation profileFromJson = profile;

                if (profileFromJson.id == authUserId.ToString())
                {
                    User originalProfile = userManager.GetUser(authUserId);
                    if (originalProfile != null)
                    {
                        //model sync
                        originalProfile.description = (profileFromJson.description != null) ? profileFromJson.description : null;
                        originalProfile.email = (profileFromJson.email != null) ? profileFromJson.email : null;
                        //if (profileFromJson.links != null)
                        //{
                        //    originalProfile.facebookLink = (profileFromJson.links.facebookLink != null) ? profileFromJson.links.facebookLink : null;
                        //    originalProfile.twitterLink = (profileFromJson.links.twitterLink != null) ? profileFromJson.links.twitterLink : null;
                        //    originalProfile.linkedinLink = (profileFromJson.links.linkedinLink != null) ? profileFromJson.links.linkedinLink : null;
                        //}

                        originalProfile.firstName = (profileFromJson.firstName != null) ? profileFromJson.firstName : null;
                        originalProfile.lastName = (profileFromJson.lastName != null) ? profileFromJson.lastName : null;
                        originalProfile.location = (profileFromJson.location != null) ? profileFromJson.location : null;
                        originalProfile.major = (profileFromJson.major != null) ? profileFromJson.major : null;
                        originalProfile.phoneNumber = (profileFromJson.phoneNumber != null) ? profileFromJson.phoneNumber : null;
                        originalProfile.projectOrder = (profileFromJson.projectOrder != null) ? profileFromJson.projectOrder : null;
                        originalProfile.resume = (profileFromJson.resume != null) ? profileFromJson.resume : null;
                        originalProfile.organization = (profileFromJson.organization != null) ? profileFromJson.organization : null;
                        originalProfile.tagLine = (profileFromJson.tagLine != null) ? profileFromJson.tagLine : null;
                        originalProfile.title = (profileFromJson.title != null) ? profileFromJson.title : null;

                        userManager.UpdateUser(originalProfile);
                        JsonModels.ProfileInformation returnProfile = userManager.GetProfileJson(originalProfile);
                        return AddSuccessHeader(Serialize(returnProfile));
                    }
                    else
                    {
                        return AddErrorHeader("The user does not exist in the database");
                    }
                }
                else
                {
                    return AddErrorHeader("User is not the profile owner, and thus is not authorized to edit this profile!");
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, "UserController - UpdateProfile", ex.StackTrace);
                return AddErrorHeader("Something went wrong while updating this Profile.");
            }
        }