Exemplo n.º 1
0
        public async Task <ActionResult> DeleteOrder(ConfirmOrderDTO orderDetails)
        {
            NoteModel note = await noteCosmosDBService.GetNote(orderDetails.NoteId);

            if (note != null)
            {
                string shopName = note.Shops.First(x => x.ShopEmail.Equals(orderDetails.ShopEmail)).ShopName;
                note.Shops.RemoveAll(x => x.ShopEmail.Equals(orderDetails.ShopEmail));
                if (await noteCosmosDBService.ReplaceDocumentAsync(note.SelfLink, note))
                {
                    string notification = $"The shop {shopName} has cancelled the order";
                    var    data         = new Dictionary <string, string>();
                    data.Add("orderid", note.Id);
                    var notificationData = new NotificationData()
                    {
                        msgBody   = notification,
                        msgTitle  = "Shop has cancelled the order",
                        tokenList = note.PhoneGuid
                                    //options = data
                    };
                    pushNotificationService.SendNotification(notificationData);
                    return(Ok("Order Cancelled Successfully"));
                }
                return(StatusCode(500, "Unable to cancel the order"));
            }
            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"));
        }
 public static async Task <ServerResponse <object, OrderErrorMessage> > RefuseOrder(int orderID, ConfirmOrderDTO data)
 {
     return(await FetchApi.PostAsync <OrderErrorMessage>($"orders/{orderID}/refuse", data));
 }