コード例 #1
0
        /// <summary>
        /// Saves the new asset or updates the old one.
        /// </summary>
        /// <returns></returns>
        protected override async Task OnSubmit()
        {
            //Creates a new Dto with the new data.
            var asset = new AssetDto
            {
                AssetName                = AssetName.Value,
                Broken                   = IsBroken,
                PurchaseDate             = PurchaseDate.Value,
                CountryOfDepartment      = CountryOfDepartment.Value,
                Department               = Department.Value,
                EmailAddressOfDepartment = EmailAddressOfDepartment.Value,
                Id = assetId
            };

            try
            {
                //Send the request to save/update the asset.
                AssetDto result;
                if (IsEditing)
                {
                    result = await Http.UpdateItemAsync("asset", asset);
                }
                else
                {
                    result = await Http.AddItemAsync("asset", asset);
                }

                //Navigates back if result was successful
                if (result != null)
                {
                    await NavService.GoBack();
                }
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
        }