public HttpResponseMessage GetFullMedCenters(int skip = 0, int take = 0, decimal latitude = 0, decimal longitude = 0, bool inRange = false, string city = "", string country = "")
        {
            IList <DonationsCentersListViewModel> donationsCentersListViewModel = new List <DonationsCentersListViewModel>();

            IEnumerable <DonationsCenter> donationsCenters = this.donationsCentersManager.GetItems() as IEnumerable <DonationsCenter>;

            IEnumerable <DonationsCenter> query = donationsCenters;

            if (inRange)
            {
                query = query.Where(r => RadiusChecker.GetDistance((double)latitude, (double)longitude, (double)r.Latitude, (double)r.Longitude) < 25.0D);
            }

            if (!string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(country))
            {
                query = query.Where(r => r.City.ToLower() == city.ToLower() && r.Country.ToLower() == country.ToLower());
            }

            query = query.Skip(skip).Take(take);


            foreach (DonationsCenter center in query)
            {
                donationsCentersListViewModel.Add(new DonationsCentersListViewModel()
                {
                    Id          = center.Id,
                    Address     = center.Address,
                    Latitude    = center.Latitude,
                    Longitude   = center.Longitude,
                    Name        = center.Name,
                    Email       = center.Email,
                    PhoneNumber = center.PhoneNumber,
                    Image       = center.Image
                });
            }


            HttpResponseMessage resp = new HttpResponseMessage();

            resp.Content = new StringContent(JsonConvert.SerializeObject(donationsCentersListViewModel));
            resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return(resp);
        }
Esempio n. 2
0
        public HttpResponseMessage GetFullRequests(int skip = 0, int take = 0, decimal latitude = 0, decimal longitude = 0, bool inRange = false, string city = "", string country = "", [FromUri] int[] bloodTypes = null)
        {
            IList <RequestUserListViewModel> requestsListViewModel = new List <RequestUserListViewModel>();

            IEnumerable <User>  users  = this.usersManager.GetItems() as IEnumerable <User>;
            IEnumerable <Claim> claims = (HttpContext.Current.User as ClaimsPrincipal).Claims;

            string userEmail = claims.Where(c => c.Type == ClaimTypes.Email).Select(c => c.Value).FirstOrDefault();

            if (!string.IsNullOrEmpty(userEmail))
            {
                User user = users.Where(u => u.Email == userEmail).FirstOrDefault();

                if (user != null)
                {
                    IEnumerable <DonationsRequest> requests = this.requestsManager.GetItems() as IEnumerable <DonationsRequest>;

                    IEnumerable <DonationsRequest> query = requests;

                    if (inRange)
                    {
                        query = query.Where(r => RadiusChecker.GetDistance((double)latitude, (double)longitude, (double)r.Latitude, (double)r.Longitude) < 15.0D);
                    }

                    if (!string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(country))
                    {
                        query = query.Where(r => r.City.ToLower() == city.ToLower() && r.Country.ToLower() == country.ToLower());
                    }

                    if (bloodTypes != null && bloodTypes.Length > 0)
                    {
                        query = query.Where(r => bloodTypes.Contains((int)r.RequestedBloodType));
                    }

                    query = query.Skip(skip).Take(take).OrderByDescending(r => r.Date);


                    foreach (DonationsRequest request in query)
                    {
                        User requestUser = this.usersManager.GetItem(request.OwnerId ?? Guid.Empty) as User;

                        if (requestUser != null)
                        {
                            requestsListViewModel.Add(new RequestUserListViewModel()
                            {
                                Id   = request.Id,
                                Date = request.Date,
                                RequestedBloodQuantity = request.RequestedBloodQuantityInMl,
                                BloodType   = request.RequestedBloodType,
                                Address     = request.Address,
                                Latitude    = request.Latitude,
                                Longitude   = request.Longitude,
                                Name        = string.Format("{0} {1}", requestUser.FirstName, requestUser.LastName),
                                Email       = requestUser.Email,
                                PhoneNumber = requestUser.PhoneNumber,
                                Image       = requestUser.Image
                            });
                        }
                    }
                }
            }

            HttpResponseMessage resp = new HttpResponseMessage();

            resp.Content = new StringContent(JsonConvert.SerializeObject(requestsListViewModel));
            resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return(resp);
        }