Пример #1
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var value = actionContext.Request.Headers.Authorization;

            try
            {
                PersonToken pt = db.PersonToken.Where(x => x.Token == value.Scheme).SingleOrDefault();
                if (pt != null)
                {
                    pt.DateLastLogin = DateTime.Now;
                    db.SaveChanges();
                }
                else
                {
                    //dynamic cResponse = new ExpandoObject();
                    //cResponse.Result = "-1";
                    //cResponse.Feedback = "Valid token could not found";
                    //JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse));

                    actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
                }
            }
            catch (Exception ex)
            {
                actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
            }

            actionContext.ActionArguments[ParameterName] = value;
        }
        // [AcceptVerbs("PATCH")]
        public object PatchFeedback(int id, Delta <Feedback> feedback)
        {
            dynamic cResponse = new ExpandoObject();

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

                Feedback dbFeedback = db.Feedback.SingleOrDefault(p => p.FeedbackID == id);
                if (dbFeedback == null)
                {
                    cResponse.Result      = "-1";
                    cResponse.Description = "ID: " + id + ", Not Found";
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                feedback.Patch(dbFeedback);
                db.SaveChanges();

                cResponse.Result      = "0";
                cResponse.Description = "Object Updated";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
            catch (Exception ex)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Your request could not executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }
        public object PatchStory(int id, Delta <Story> story)
        {
            dynamic cResponse = new ExpandoObject();

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

                Story dbStory = db.Story.SingleOrDefault(p => p.StoryID == id);
                if (dbStory == null)
                {
                    cResponse.Result      = "-1";
                    cResponse.Description = "ID: " + id + ", Not Found";
                    return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
                }

                story.Patch(dbStory);
                db.SaveChanges();

                cResponse.Result      = "0";
                cResponse.Description = "Story Updated";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
            catch (Exception ex)
            {
                cResponse.Result      = "-1";
                cResponse.Description = "Your request could not executed";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
            }
        }
Пример #4
0
        public object PatchPerson(int id, Delta <Person> person)
        {
            dynamic cResponse = new ExpandoObject();

            Person dbPerson = db.Person.SingleOrDefault(p => p.PersonID == id);

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

            person.Patch(dbPerson);
            db.SaveChanges();

            cResponse.Result      = "0";
            cResponse.Description = "Person Updated";
            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
        }
Пример #5
0
        // PUT: api/Activitiy/5
        //[ResponseType(typeof(void))]
        public object PatchActivity(int id, Delta <Activity> activity)
        {
            dynamic cResponse = new ExpandoObject();

            Activity dbActivity = db.Activity.SingleOrDefault(p => p.ActivityID == id);

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

            activity.Patch(dbActivity);
            db.SaveChanges();

            cResponse.Result      = "0";
            cResponse.Description = "Activity Updated";
            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
        }
Пример #6
0
        public object PatchMoment(int id, Delta <Moment> moment)
        {
            dynamic cResponse = new ExpandoObject();

            Moment dbMoment = db.Moment.SingleOrDefault(p => p.MomentID == id);

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

            moment.Patch(dbMoment);
            db.SaveChanges();

            cResponse.Result      = "0";
            cResponse.Description = "Object Updated";
            return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cResponse)));
        }
Пример #7
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)));
        }
Пример #8
0
        public static string TokenCheck(string token)
        {
            MomenticEntities db = new MomenticEntities();

            try
            {
                PersonToken pt = db.PersonToken.Where(x => x.Token == token).SingleOrDefault();
                if (pt != null)
                {
                    pt.DateLastLogin = DateTime.Now;
                    db.SaveChanges();
                    return("0");
                }
                else
                {
                    return("-1");
                }
            }
            catch (Exception ex)
            {
                return("-1");
            }
        }
Пример #9
0
        public static string TokenCreate(int personID)
        {
            MomenticEntities db = new MomenticEntities();

            try
            {
                string temp = Guid.NewGuid().ToString();

                PersonToken pt = new PersonToken();
                pt.DateCreated   = DateTime.Now;
                pt.DateLastLogin = DateTime.Now;
                pt.PersonID      = personID;
                pt.Token         = temp;

                db.PersonToken.Add(pt);
                db.SaveChanges();

                return(temp);
            }
            catch (Exception ex)
            {
                return("-1");
            }
        }