Example #1
0
        public async Task <ActionResult> ConfirmNoteItems(ConfirmNoteItemsDTO availableItems)
        {
            NoteModel note = await noteCosmosDBService.GetNote(availableItems.NoteID);

            if (note != null)
            {
                Model.Shop shop = note.Shops.First(x => x.ShopEmail.Equals(availableItems.UserEmail));
                shop.Notes = mapper.Map <NoteModel>(availableItems).Notes;
                note.Shops.RemoveAll(x => x.ShopEmail.Equals(availableItems.UserEmail));
                shop.ResponseTime = DateTime.Now;
                shop.ShopStatus   = 1;
                note.Shops.Add(shop);
                if (await noteCosmosDBService.ReplaceDocumentAsync(note.SelfLink, note))
                {
                    string title = $"The shop {shop.ShopName} has responded to your order";
                    var    data  = new Dictionary <string, string>();
                    data.Add("orderid", note.Id);
                    var notificationData = new NotificationData()
                    {
                        msgBody   = title,
                        msgTitle  = "A Shop has responed to your order",
                        tokenList = note.PhoneGuid
                                    //options = data
                    };

                    pushNotificationService.SendNotification(notificationData);
                    return(Ok("Note Successfully Updated"));
                }
                return(StatusCode(500, "Unable to update the status"));
            }
            return(BadRequest("Specified Note doesn't exist"));
        }
        public async Task <ActionResult> ConfirmOrderToShop(ConfirmOrderDTO confirmOrder)
        {
            NoteModel note = await noteCosmosDBService.GetNote(confirmOrder.NoteId);

            if (note != null)
            {
                var shop = note.Shops.First(x => x.ShopEmail.Equals(confirmOrder.ShopEmail));
                shop.Accepted = true;
                note.Shops.RemoveAll(x => x.ShopEmail != confirmOrder.ShopEmail);
                note.Status = 1;
                if (await noteCosmosDBService.ReplaceDocumentAsync(note.SelfLink, note))
                {
                    string notification = $"The user {note.UserId} has confirmed the order with you";
                    var    data         = new Dictionary <string, string>();
                    data.Add("orderid", note.Id);
                    var notificationData = new NotificationData()
                    {
                        msgBody   = notification,
                        msgTitle  = "User has confirmed the order with you",
                        tokenList = shop.PhoneGuid
                                    //options = data
                    };
                    pushNotificationService.SendNotification(notificationData);
                    return(Ok("Order Confirmed with the shop"));
                }
                return(StatusCode(500, "Something went wrong"));
            }
            return(BadRequest("Couldn't find the note specified"));
        }