Example #1
0
        private async Task CreateStamp()
        {
            List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Title", Title)
            };

            if (FieldValidation.ValidateFields(values))
            {
                CanSaveStamp = false;
                try
                {
                    StampModel typeData = new StampModel()
                    {
                        Title = Title,
                    };
                    HttpResponseMessage result = null;
                    if (isUpdate)
                    {
                        typeData.ID        = ID;
                        typeData.CreatedBy = SelectedStamp.CreatedBy;
                        result             = await apiHelper.PutStamp(ParentLayout.LoggedInUser.Token, typeData).ConfigureAwait(false);
                    }
                    else
                    {
                        typeData.CreatedBy = ParentLayout.LoggedInUser.Name;
                        result             = await apiHelper.PostStamp(ParentLayout.LoggedInUser.Token, typeData).ConfigureAwait(false);
                    }
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show($"Stamp Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                        await GetStamps();

                        ClearFields();
                        IsUpdate = false;
                    }
                    else
                    {
                        MessageBox.Show("Error in saving stamp", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    CanSaveStamp = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    CanSaveStamp = true;
                }
            }
        }