State { get; set; }
protected User CurrentUser
{
get
{
return (UserManagerSingleton.GetUser(UserManager, HttpContextAccessor.HttpContext.User));
}
}
private Guid ID { get; set; }
protected TDataObj Obj;
protected override async Task OnInitializedAsync()
{
if (_userAuthorizationStrategy.IsUserBlocked(CurrentUser.Id))
{
NavigationManager.NavigateTo("/_403");
}
InitPreloadParam();
InitDataObject();
InitModalVisible();
OnInitExt();
StateHasChanged();
}
private void InitModalVisible()
{
if (IsModal)
{
IsVisible = true;
}
}
private void InitDataObject()
{
Obj = Dal.New();
if (ObjectOperation != EObjectOperation.Add)
{
//BtnLabel = "Обновить";
Obj = Dal.FindById(ID);
}
}
private void InitPreloadParam()
{
InitModelParams();
InitObjectOperation();
}
public object GetParamValue(string paramName)
{
return ModelParams?.Where(x => x.ParamName == paramName).FirstOrDefault()?.ParamValue;
}
private void InitModelParams()
{
var id = GetParamValue("id");
if (id != null)
{
ID = new Guid(id.ToString());
}
}
private void InitObjectOperation()
{
ObjectOperation = EObjectOperation.None;
var id = GetParamValue("id");
if (id == null || id.ToString() == string.Empty)
{
ObjectOperation = EObjectOperation.Add;
}
}
public void SetObjectOperation(EObjectOperation objectOperation)
{
ObjectOperation = objectOperation;
}
public virtual async Task SaveAsync()
{
var user = await UserManager.GetUserAsync(HttpContextAccessor.HttpContext.User);
try
{
PrepareForInsert();
if (ObjectOperation == EObjectOperation.Add)
{
Obj.UserCreateID = user.Id;
Obj.UserUpdateID = user.Id;
//Dal.Create(Obj);
//MessageService.Info("Запись добавлена");
}
else
{
Obj.UserUpdateID = user.Id;
//Dal.Update(Obj);
//MessageService.Info("Запись обновлена");
}
BeforeSave();
await Dal.SaveAsync(Obj);
AfterSave();
MessageService2.Add("Запись сохранена", MatToastType.Success, "Сохранение");
State.DataChanged();
OnCloseDelegate?.Invoke();
if (IsModal)
{
ModalService.Close();
}
}
catch (Exception e)
{
//Console.Error.WriteLine(e.Message);
MessageService2.Add(e.Message, MatToastType.Danger, "Сохранение");
}
StateHasChanged();
return;
}
public virtual async Task Save()
{
var user = await UserManager.GetUserAsync(HttpContextAccessor.HttpContext.User);
try
{
PrepareForInsert();
if (ObjectOperation == EObjectOperation.Add)
{
Obj.UserCreateID = user.Id;
Obj.UserUpdateID = user.Id;
Кидай код на pastebin.com или gist.github.com плиз
Обсуждают сегодня