Example #1
0
        public async Task <IHttpActionResult> DeletePersonFollowing(int id)
        {
            PersonFollowing personFollowing = await db.PersonFollowing.FindAsync(id);

            if (personFollowing == null)
            {
                return(NotFound());
            }

            db.PersonFollowing.Remove(personFollowing);
            await db.SaveChangesAsync();

            return(Ok(personFollowing));
        }
Example #2
0
        public object PatchPersonFollowing(int id, int secondary, Delta <PersonFollowing> personFollowing)
        {
            dynamic cResponse = new ExpandoObject();

            PersonFollowing dbFollowing = db.PersonFollowing.SingleOrDefault(p => p.PersonID == id && p.SecondaryPersonID == secondary);

            if (dbFollowing == null)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "ID: " + id + ", Not Found";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            dbFollowing.DateAccepted = DateTime.Now;

            personFollowing.Patch(dbFollowing);
            db.SaveChanges();

            cResponse.Result      = "0";
            cResponse.Description = "Object Updated";
            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
        }
Example #3
0
        public async Task <object> PostPersonFollowing(PersonFollowing personFollowing)
        {
            dynamic cResponse = new ExpandoObject();

            if (personFollowing.PersonID == personFollowing.SecondaryPersonID)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "You cannot follow yourself";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }

            try
            {
                if (!ModelState.IsValid)
                {
                    cResponse.Result      = "-1";
                    cResponse.Description = ModelState;
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                personFollowing.DateRequest = DateTime.Now;
                personFollowing.IsAccepted  = false;

                db.PersonFollowing.Add(personFollowing);
                await db.SaveChangesAsync();

                cResponse.Result      = "0";
                cResponse.Description = "Person Following Added";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
            catch
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Exception, your request could not be executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }