Exemplo n.º 1
0
        public void DeleteRecord(string index)
        {
            try
            {
                //Step 1 Code to delete the object from the database
                AssetManagementCategory n = new AssetManagementCategory();
                n.recordId         = index;
                n.name             = "";
                n.deliveryDuration = 0;



                PostRequest <AssetManagementCategory> req = new PostRequest <AssetManagementCategory>();
                req.entity = n;
                PostResponse <AssetManagementCategory> res = _assetManagementService.ChildDelete <AssetManagementCategory>(req);
                if (!res.Success)
                {
                    //Show an error saving...
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    Common.errorMessage(res);
                    return;
                }
                else
                {
                    //Step 2 :  remove the object from the store
                    Store1.Remove(index);

                    //Step 3 : Showing a notification for the user
                    Notification.Show(new NotificationConfig
                    {
                        Title = Resources.Common.Notification,
                        Icon  = Icon.Information,
                        Html  = Resources.Common.RecordDeletedSucc
                    });
                }
            }
            catch (Exception ex)
            {
                //In case of error, showing a message box to the user
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorDeletingRecord).Show();
            }
        }
Exemplo n.º 2
0
        protected void SaveNewRecord(object sender, DirectEventArgs e)
        {
            //Getting the id to check if it is an Add or an edit as they are managed within the same form.
            string id = e.ExtraParams["id"];

            string obj = e.ExtraParams["values"];
            AssetManagementCategory b = JsonConvert.DeserializeObject <AssetManagementCategory>(obj);


            // Define the object to add or edit as null

            if (string.IsNullOrEmpty(currentCategory.Text))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store
                    PostRequest <AssetManagementCategory> request = new PostRequest <AssetManagementCategory>();
                    request.entity = b;
                    PostResponse <AssetManagementCategory> r = _assetManagementService.ChildAddOrUpdate <AssetManagementCategory>(request);
                    b.recordId = r.recordId;

                    //check if the insert failed
                    if (!r.Success)//it maybe be another condition
                    {
                        //Show an error saving...

                        Common.errorMessage(r);
                        return;
                    }
                    else
                    {
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordSavingSucc
                        });

                        currentCategory.Text = r.recordId;
                    }
                }
                catch (Exception ex)
                {
                    //Error exception displaying a messsage box
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show();
                }
            }
            else
            {
                //Update Mode

                try
                {
                    PostRequest <AssetManagementCategory> request = new PostRequest <AssetManagementCategory>();

                    request.entity          = b;
                    request.entity.recordId = currentCategory.Text;
                    PostResponse <AssetManagementCategory> r = _assetManagementService.ChildAddOrUpdate <AssetManagementCategory>(request);                      //Step 1 Selecting the object or building up the object for update purpose

                    //Step 2 : saving to store

                    //Step 3 :  Check if request fails
                    if (!r.Success)//it maybe another check
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        Common.errorMessage(r);
                        return;
                    }
                    else
                    {
                        Store1.Reload();
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordUpdatedSucc
                        });
                        this.EditRecordWindow.Close();
                    }
                }
                catch (Exception ex)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                }
            }
        }