Base solution for your next web application

Activities of "sparkyjr"

Hi,

I am new to ASP.Net Zero and ABP.

I have created a custom filter to ignore the rows having IsArchived property set to 1, i.e. true. Everything works fine. It filters out the rows with this column == 1. Now, I want to fetch the rows where IsArchived == 1. I mean, I want to fetch the archived rows now. I tried disabling the custom filter in my controller action, as follows:

public class ArchivedController : Controller
    {
        private ArchivedAppService archivedAppService;
        IUnitOfWorkManager unitOfWorkManager;

        public ArchivedController(IUnitOfWorkManager _unitOfWorkManager, ArchivedAppService _archivedAppService)
        {
            archivedAppService = _archivedAppService;
            unitOfWorkManager = _unitOfWorkManager;
        }

        public ActionResult Index(int id)
        {
            unitOfWorkManager.Current.DisableFilter("ArchiveFilter");  //Error: "Object reference not set to an instance of an object."
            var output = archivedAppService.GetArchived(id);
            ArchivedViewModel model = new ArchivedInitiativesViewModel(output);

            return View(model);
        }
    }

The Current property of unitOfWorkManager is null. So, it throws error.

Please tell me what could be the reason. How and where do I set the unit of work?

Thank you in advance!

That worked. I will have a look at the UOW document. Thank you so much hikalkan!

Hi,

I am trying to inject a service through the constructor in WebViewPageBase.cs lying in Web Project -> Views -> WebViewPageBase but its not allowing. Does Dependency Injection through the constructor not work for WebViewPageBase.cs class?

Thanking you in advance.

Hi,

When testing for multiple Tenants the TenantId is getting cached in AbpSession. Just to recreate this scenario you could check AccountController, and try logging with different Tenants.

Thank you for your reply!

But when I login with two different Tenant users , two different tabs of the same browser why does UserManager.AbpSession.TenantId show me previous TenantId (from first tab of the browser) and not the latest one? And hence the Repositories and Services bring me data for the previous Tenant (from first tab of the browser) and not the current one.

Also, I am using Background Worker to send out emails (every 24hours) with some data, specific to the Tenant. I couldn't add the worker in the pre-initialize method of the project module file. I need a TenantId, so, I was forced to add it in the Login method, and call an Application Service, where I need TenantId. Now, because of the issue explained in the paragraph above, I am getting wrong data.

Am I doing anything wrong here? From where can I get the correct TenantId?

Thanks in advance!

Hi,

What all are the possible cases when the CreatorUserId goes as null?

Thanks for your reply!

We are using Background Worker and not Background Job. We need to fire a method periodically to check if some data in some tables has been updated or not. If it has not been updated, we are sending out an email to the users informing them about the pending updates.

Now, if I add/register the worker in the pre-initialize method in the project module file, then, it will be difficult for us to fetch the data, because, we don't get the TenantId there. So, we have added/registered the worker in the LogIn() method. The worker calls an Application Service and does everything for us.

Hope this explanation helps!

Thanks in advance!

<cite>hikalkan: </cite> It's saved as null if the entity is created when user did not login (so, we don't know userid).

Thanks for your reply!

But, that's not the case. User is logged in. We update a record using either InsertOrUpdateAsync or UpdateAsync method. The LastModifierUserId gets updated with correct UserId, but, the CreatorUserId becomes NULL. That's a big issue for us. Could you please check and tell us why does this happen?

Thanks in advance!

Hi ,

This is my code

[HttpPost] [UnitOfWork] [DisableAuditing] public virtual async Task<JsonResult> Login(LoginViewModel loginModel, string returnUrl = "", string returnUrlHash = "") { CheckModelState();

        _unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant);

        var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, loginModel.TenancyName);

        if (loginResult.User.ShouldChangePasswordOnNextLogin)
        {
            loginResult.User.SetNewPasswordResetCode();

            return Json(new MvcAjaxResponse
            {
                TargetUrl = Url.Action(
                    "ResetPassword",
                    new ResetPasswordViewModel
                    {
                        UserId = SimpleStringCipher.Encrypt(loginResult.User.Id.ToString()),
                        ResetCode = loginResult.User.PasswordResetCode
                    })
            });
        }

        if (loginResult.User.TenantId.HasValue)
        {
            var trMap = await _tennantRhythmMapReository.FirstOrDefaultAsync(x => x.TenantId == (int)loginResult.User.TenantId);

            HttpCookie cookie = new HttpCookie("TrackingRhythmType");
            cookie.Value = (await _trackingRhythmReository.FirstOrDefaultAsync(x => x.Id == trMap.TrackingRhythmId)).TrackingRhythmType;
            Response.SetCookie(cookie);

            HttpCookie cookieTenantName = new HttpCookie("TenantName");
            cookieTenantName.Value = loginResult.User.Tenant.TenancyName;
            Response.SetCookie(cookieTenantName);

            _backgroundWorkerManager.Add(_actualUpdationDueWorker);

            // sets PersonalizedCaptionsCookie in PersonalizedCaptionsService.
            //await _personalizedCaptionService.SetPersonalizedCaptionsCookie(loginResult.User.TenantId);
        }
        else
        {
            var c = new HttpCookie("TenantName");
            c.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(c);
        }

        await SignInAsync(loginResult.User, loginResult.Identity, loginModel.RememberMe);

        if (string.IsNullOrWhiteSpace(returnUrl))
        {
            returnUrl = Url.Action("Index", "Application");
        }

        if (!string.IsNullOrWhiteSpace(returnUrlHash))
        {
            returnUrl = returnUrl + returnUrlHash;
        }

        return Json(new MvcAjaxResponse { TargetUrl = returnUrl });
    }

Hi,

We have used Background Worker to send out emails every 24 hours. The problem is, the client never received any emails. We think that the application gets removed after certain time, and is not active on the server.

How do I keep the application alive and active all the time?

Thanks in advance!

Showing 1 to 10 of 71 entries