Example #1
0
        public async Task <IActionResult> Status(Int64 id)
        {
            Console.WriteLine($"/pollinator/Upload/Status/{id}");

            var user = await _userManager.GetUserAsync(User);

            var asset = await _assetManager.FindByIdAsync(id);

            Int64 nextId = user.NextAssetId;

            // we're only successful when
            //  * the asset exists
            //  * the asset is used
            //  * the asset has the same author
            //    as the currently logged in user
            //  * the id is the same as the user's reserved id
            bool success = (asset != null &&
                            asset.Used &&
                            asset.AuthorId == user.Id &&
                            user.NextAssetId == id);

            // when the requirements have been met,
            // reserve a new asset
            if (success)
            {
                // when reserving a new asset fails, error out
                if (!await _assetManager.ReserveAsync(user))
                {
                    return(StatusCode(500));
                }

                // tell the client about the new id
                nextId = user.NextAssetId;
            }

            return(XmlBuilder.CreateFromTemplate(
                       new StatusTemplate(nextId, success)
                       ).ToContentResult());
        }