public async Task <ActionResult> SubmitNote(NoteDTO noteDTO)
        {
            List <ShopModel> shops = await userCosmosDBService.GetShops(noteDTO.Category);

            if (shops?.Count > 0)
            {
                List <ShopModel> nearbyShops      = DistanceCalculator.GetDistance(shops, noteDTO.Latitude, noteDTO.Longitude);
                string           body             = string.Format("You have received a new order request from {0}", noteDTO.UserPhoneNumber);
                var phoneGuidList                 = nearbyShops.Where(s => s.PhoneGuid != null)?.Select(shop => shop.PhoneGuid).ToList();
                NotificationData notificationData = null;
                var data = new Dictionary <string, string>();
                data.Add("orderid", "test");
                if (phoneGuidList.Count() > 0)
                {
                    if (phoneGuidList.Count() == 1)
                    {
                        notificationData = new NotificationData()
                        {
                            msgBody   = body,
                            msgTitle  = "You have received a new order request",
                            tokenList = phoneGuidList[0]
                                        //options = data
                        };
                    }
                    else
                    {
                        notificationData = new NotificationData()
                        {
                            msgBody   = body,
                            msgTitle  = "You have received a new order request",
                            tokenList = phoneGuidList
                                        //options = data
                        };
                    }

                    pushNotificationService.SendNotification(notificationData);
                }

                //Mapping
                NoteModel  note       = mapper.Map <NoteModel>(noteDTO);
                ShopsModel shopsModel = new ShopsModel();
                shopsModel.ShopModel = nearbyShops;
                Model.Shops shopsresult = mapper.Map <Model.Shops>(shopsModel);
                note.Shops = shopsresult.Shop;

                //Assigning fields
                note.NoteTime = DateTime.Now;
                note.Status   = 0;

                note = await noteCosmosDBService.CreateAndReturnDocumentAsync(note);

                if (note != null)
                {
                    return(Ok(mapper.Map <NoteInfo>(note)));
                }
            }
            return(Ok("No shops found with the matching criteria"));
        }
Exemple #2
0
        public async Task <ActionResult> GetNearbyShops(ShopsNearbyDTO shopsNearbyDTO)
        {
            List <ShopModel> shops = await userCosmosDBService.GetShops(shopsNearbyDTO.TypeOfBusiness);

            if (shops?.Count > 0)
            {
                ShopsModel shopsModel = new ShopsModel();
                shopsModel.ShopModel = DistanceCalculator.GetDistance(shops, shopsNearbyDTO.Latitude, shopsNearbyDTO.Longitude);
                return(Ok(mapper.Map <ResponseModel.Shops>(shopsModel).Shop));
            }
            return(Ok("Couldn't find any shops nearby"));
        }