コード例 #1
0
        public async Task CmdAddOrUpdateTodo()
        {
            IsButtonDisabled = true;
            StateHasChanged();

            if (LocalData.CurrTodo.HasDueDate)
            {
                if (LocalData.CurrTodo.DueDate <= LocalFunctions.ToLocalDate(DateTime.Now).AddMinutes(3))
                {
                    LocalFunctions.AddError("Due date should be minimum after 3 minute from now", MethodBase.GetCurrentMethod(), false, false);
                }
            }


            LocalFunctions.Validate(LocalData.CurrTodo);


            if (LocalFunctions.HasError())
            {
                LocalFunctions.DisplayErrors();
            }
            else
            {
                string a = string.Empty;

                if (LocalData.AddOrUpdateMode)
                {
                    LocalData.CurrTodo.UserID = LocalData.CurrTSUser.ID;
                    a = await WebApiFunctions.CmdAddTodo(LocalData.CurrTodo);
                }
                else
                {
                    if (!GlobalFunctions.AreEqualTwoObjects(LocalData.CurrTodo, LocalData.BeforeUpdateTodo))
                    {
                        a = await WebApiFunctions.CmdUpdateTodo(LocalData.CurrTodo);
                    }
                    else
                    {
                        LocalFunctions.AddMessage("Todo properties not updated", true, false);
                        return;
                    }
                }

                if (a.Equals("OK"))
                {
                    LocalData.TsTodosList = new List <TSTodoEx>();

                    LocalData.btModal.Close();

                    LocalData.EventConsumerName = "TodosPage";
                    LocalData.componentBridge.InvokeRefresh();
                }
                else
                {
                    LocalFunctions.AddError(a, MethodBase.GetCurrentMethod(), true, false);
                }
            }

            IsButtonDisabled = false;
        }