Esempio n. 1
0
        public IHttpActionResult Rate(int recordStoreId, ODataActionParameters parameters)
        {
            RecordStore recordStore = dbContext.RecordStores.FirstOrDefault(r => r.RecordStoreId == recordStoreId);

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

            object value;
            int    rating;
            int    personId;

            if (!parameters.TryGetValue("rating", out value) || !int.TryParse(value.ToString(), out rating) ||
                !parameters.TryGetValue("personId", out value) || !int.TryParse(value.ToString(), out personId))
            {
                return(BadRequest());
            }

            Person person = dbContext.People.FirstOrDefault(p => p.PersonId == personId);

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

            recordStore.Ratings.Add(new Rating {
                RatedBy = person, Value = rating
            });

            return(this.CreateOKHttpActionResult(dbContext.SaveChanges() >= 0));
        }
Esempio n. 2
0
        public IHttpActionResult RemoveRatings(ODataActionParameters parameters)
        {
            object value;
            int    personId;

            if (!parameters.TryGetValue("personId", out value) || !int.TryParse(value.ToString(), out personId))
            {
                return(BadRequest());
            }

            Person person = dbContext.People.FirstOrDefault(p => p.PersonId == personId);

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

            foreach (var recordStore in dbContext.RecordStores.Include("Ratings").Include("Ratings.RatedBy"))
            {
                List <Rating> ratings = recordStore.Ratings.Where(rt => rt.RatedBy == person).ToList();
                foreach (var rating in ratings)
                {
                    recordStore.Ratings.Remove(rating);
                }
            }

            return(this.CreateOKHttpActionResult(dbContext.SaveChanges() >= 0));
        }
Esempio n. 3
0
        public static T GetValueSafe <T>(this ODataActionParameters parameters, string key, T defaultValue = default)
        {
            if (parameters != null && key.HasValue() && parameters.TryGetValue(key, out var value))
            {
                return(value.Convert(defaultValue));
            }

            return(defaultValue);
        }
Esempio n. 4
0
        private T FindParameter <T>(ODataActionParameters parameters, string parameterName)
        {
            object output;

            if (!parameters.TryGetValue(parameterName, out output))
            {
                return(default(T));
            }
            return((T)output);
        }
Esempio n. 5
0
        public static T Find <T>(this ODataActionParameters parameters, string parameterName)
        {
            object output;

            if (!parameters.TryGetValue(parameterName, out output))
            {
                return(default(T));
            }
            return((T)output);
        }
Esempio n. 6
0
        public IActionResult SetProfile(int key, ODataActionParameters parameters)
        {
            object value;

            parameters.TryGetValue("profile", out value);
            int profileId = (int)value;

            // link user to the profile logic goes here

            return(Ok());
        }
Esempio n. 7
0
        public static T GetValue <T>(this ODataActionParameters parameters, string key)
        {
            object result;

            if (parameters.TryGetValue(key, out result) && result is T)
            {
                return((T)result);
            }

            return(default(T));
        }
Esempio n. 8
0
        public IHttpActionResult ByRefs(ODataActionParameters p)
        {
            object value;
            bool   bOk = p.TryGetValue("refs", out value);

            Assert.True(bOk);

            IEnumerable <InvoiceReference> refs = value as IEnumerable <InvoiceReference>;

            Assert.NotNull(refs);
            Assert.Equal(3, refs.Count());

            return(Ok(String.Join(",", refs.Select(e => e.InvoiceNumber + "|" + e.SupplierId))));
        }
        public IHttpActionResult RemoveRatings(ODataActionParameters parameters)
        {
            // from the param dictionary, get the personid
            int    personId;
            object outputFromDictionary;

            if (!parameters.TryGetValue("personId", out outputFromDictionary))
            {
                return(NotFound());
            }

            if (!int.TryParse(outputFromDictionary.ToString(), out personId))
            {
                return(NotFound());
            }

            // get the RecordStores that were rated by the person with personId
            var recordStoresRatedByCurrentPerson = _ctx.RecordStores
                                                   .Include("Ratings").Include("Ratings.RatedBy")
                                                   .Where(p => p.Ratings.Any(r => r.RatedBy.PersonId == personId)).ToList();

            // remove those ratings
            foreach (var store in recordStoresRatedByCurrentPerson)
            {
                // get the ratings by the current person
                var ratingsByCurrentPerson = store.Ratings
                                             .Where(r => r.RatedBy.PersonId == personId).ToList();

                for (int i = 0; i < ratingsByCurrentPerson.Count(); i++)
                {
                    store.Ratings.Remove(ratingsByCurrentPerson[i]);
                }
            }

            // save changes
            if (_ctx.SaveChanges() > -1)
            {
                // return true
                return(this.CreateOKHttpActionResult(true));
            }
            else
            {
                // Something went wrong - we expect our
                // action to return false in that case.
                // The request is still successful, false
                // is a valid response
                return(this.CreateOKHttpActionResult(false));
            }
        }
Esempio n. 10
0
        public IHttpActionResult CopyFiles(int key, ODataActionParameters parameters)
        {
            object value;

            if (!parameters.TryGetValue("createdDate", out value))
            {
                return(NotFound());
            }

            DateTimeOffset createdDate = (DateTimeOffset)value;

            createdDate.AddYears(1).AddHours(9);

            return(Ok(createdDate));
        }
Esempio n. 11
0
        public IHttpActionResult RemoveRecordStoreRatings(ODataActionParameters parameters)
        {
            // from the param dictionary, get the personId
            int    personId;
            object outputFromDictionary;

            if (!parameters.TryGetValue("personId", out outputFromDictionary))
            {
                return(NotFound());
            }

            if (!int.TryParse(outputFromDictionary.ToString(), out personId))
            {
                return(NotFound());
            }

            // get the RecordStores that were rated by the person with personId
            var recordStoresRatedByCurrentPerson = _ctx.RecordStores
                                                   .Include("Ratings").Include("Ratings.RatedBy")
                                                   .Where(p => p.Ratings.Any(r => r.RatedBy.PersonId == personId)).ToList();

            // remove those ratings
            foreach (var store in recordStoresRatedByCurrentPerson)
            {
                // get the ratings by the current person
                var ratingsByCurrentPerson = store.Ratings.Where(r => r.RatedBy.PersonId == personId).ToList();

                for (int i = 0; i < ratingsByCurrentPerson.Count; i++)
                {
                    store.Ratings.Remove(ratingsByCurrentPerson[i]);
                }
            }

            // save changes
            if (_ctx.SaveChanges() > -1)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                // something went wrong
                return(StatusCode(HttpStatusCode.InternalServerError));
            }
        }
        public bool IsEmailAvailable(ODataActionParameters parameters)
        {
            object value;

            if (parameters.TryGetValue("email", out value))
            {
                string email = value as string;
                if (email != null)
                {
                    // just for test
                    if (email == "*****@*****.**")
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public IHttpActionResult IsEmailAvailable(int key, ODataActionParameters parameters)
        {
            // Just for test
            if (key != 3)
            {
                return(NotFound());
            }

            object value;

            if (parameters.TryGetValue("email", out value))
            {
                string email = value as string;
                if (email != null)
                {
                    if (email == "*****@*****.**")
                    {
                        return(Ok("Your input email is :" + email));
                    }
                }
            }

            return(Ok(false));
        }
Esempio n. 14
0
        public IHttpActionResult Rate([FromODataUri] int key, ODataActionParameters parameters)
        {
            // get the RecordStore
            var recordStore = _ctx.RecordStores.FirstOrDefault(p => p.RecordStoreId == key);

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

            // from the param dictionary, get the rating & personId
            int    rating;
            int    personId;
            object outputFromDictionary;

            if (!parameters.TryGetValue("rating", out outputFromDictionary))
            {
                return(NotFound());
            }

            if (!int.TryParse(outputFromDictionary.ToString(), out rating))
            {
                return(NotFound());
            }

            if (!parameters.TryGetValue("personId", out outputFromDictionary))
            {
                return(NotFound());
            }

            if (!int.TryParse(outputFromDictionary.ToString(), out personId))
            {
                return(NotFound());
            }

            // the person must exist
            var person = _ctx.People.FirstOrDefault(p => p.PersonId == personId);

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

            // everything checks out, add the rating
            recordStore.Ratings.Add(new Rating()
            {
                RatedBy = person, Value = rating
            });

            // save changes
            if (_ctx.SaveChanges() > -1)
            {
                return(this.CreateOKHttpActionResult(true));
            }
            else
            {
                // Something went wrong - we expect our action to return false in that case.
                // The request is still successful, false is a valid response
                return(this.CreateOKHttpActionResult(false));
            }
        }
Esempio n. 15
0
        public IHttpActionResult CopyFiles(int key, ODataActionParameters parameters)
        {
            object value;
            if (!parameters.TryGetValue("createdDate", out value))
            {
                return NotFound();
            }

            DateTimeOffset createdDate = (DateTimeOffset)value;
            createdDate.AddYears(1).AddHours(9);

            return Ok(createdDate);
        }