I am trying to make some dynamic logic for our application, but <bp:Alert>
component don't want to cooperate.
This is masterpage ViewModel:
public class AdminMasterPageViewModel : DotvvmViewModelBase
{
public virtual AlertComponent AlertComponent { get; set; }
public DotVVM.BusinessPack.Controls.AlertType AlertType { get; set; }
public AdminMasterPageViewModel()
{
}
public override Task Init()
{
InitAlertComponents();
return base.Init();
}
private void InitAlertComponents()
{
AlertComponent = new AlertComponent
{
IsDisplayed = false,
Text = "Default",
Type = AlertComponent.Types.Info
};
AlertType = DotVVM.BusinessPack.Controls.AlertType.Info;
}
}
This is dothtml in MasterView:
<%--MAIN CONTENT BY PLACEHOLDER--%>
<div class="content-wrapper">
<bp:Alert Type="{value: AlertType}"
IsDisplayed="{value: AlertComponent.IsDisplayed}"
AllowDismiss="true"
Text="{value: AlertComponent.Text}"
AutoHideTimeout="3" />
<dot:ContentPlaceHolder ID="MainContent" />
</div>
In "Child" ViewModel I have this event:
public async void SaveUserRoleGroup()
{
UserRoleGroupDetailDTO.AppRoleForUserRoleGroupListDTOs = AppRoleListDTOs.Items.Where(i => i.IsAllowed = true).ToList();
AlertComponent = await userRoleGroupDetailFacade.CreateUserRoleGroupAsync(UserRoleGroupDetailDTO);
}
My Class representer for this Component is:
public class AlertComponent
{
public bool IsDisplayed { get; set; }
public string Text { get; set; }
public Types Type { get; set; }
public enum Types
{
Success, Info, Warning, Danger
}
}
And Finally my facade function:
public async Task<AlertComponent> CreateUserRoleGroupAsync(UserRoleGroupDetailDTO dto)
{
using (var uow = unitOfWorkProvider.Create())
{
try
{
var userRoleGroup = Mapper.Map<UserRoleGroup>(dto);
userRoleGroup.PortalSetting = portalSettingRepository.GetById(1);
repository.Insert(userRoleGroup);
await uow.CommitAsync();
}
catch (Exception e)
{
return new AlertComponent
{
Text = "Error",
IsDisplayed = true,
Type = AlertComponent.Types.Danger
};
}
}
return new AlertComponent
{
Text = "Success",
IsDisplayed = true,
Type = AlertComponent.Types.Success
};
}
As you can see, I am setting AlertComponent in SaveUserRoleGroup function, but in browser nothing happen. Iam missing changing AlertType, but it doesn't matter,it still has as default "AlertType" Info, which I set in MasterViewModel. So why alert doesn't show and not working?