예제 #1
0
        public async Task <JsonResult> UpdateBook([FromBody] BookUpdate updateBook)
        {
            var user = HttpContext.Session.Get <User>(Constants.SessionKeyState);

            string establishmentId = user.Establishment.id;
            var    result          = new Response <Book>()
            {
                Success = true
            };
            var book = new Book()
            {
                id         = updateBook.id,
                BookStatus = updateBook.BookStatus
            };

            result = _bookAgent.UpdateBook(establishmentId, book);
            if (result.Success)
            {
                var          bookResult   = result.objectResult;
                string[]     playersId    = new string[] { bookResult.PlayerId };
                Notification notification = new Notification()
                {
                    app_id             = "58997a76-3b19-4c01-9909-85d729b19784",
                    url                = "https://app.onesignal.com",
                    include_player_ids = playersId,
                    headings           = new Language()
                    {
                        en = "PUL Reservación"
                    }
                };

                if (updateBook.BookStatus == 2)
                {
                    notification.contents = new Language()
                    {
                        en = "Su reservación ha sido aceptada."
                    };
                }
                else
                {
                    notification.contents = new Language()
                    {
                        en = "Su reservación fue cancelada."
                    };
                }

                var notificationResult = _bookAgent.CreateNotification(notification);
                if (!notificationResult.Success)
                {
                    result.Error = new Error()
                    {
                        Message = $"Se actualizo la solicitud y el usuario no fue notificado, contacte al area de sistemas."
                    };
                    result.Success = false;
                }
            }

            return(await Task.FromResult(Json(result)));
        }