Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "sparkyjr"

This turned out to be a red herring. There were some reference changes that were applied to the Web project. It was for some new feature that we were experimenting on. Rolling it back (from csproj) fixed the issue for us.

Hi,

_userService.getUsers({ Filter : ""})
            .done(function(result) {
                var users = result.items;
                console.log(users);
            });

This particular code did worked for me. Thanks.

I'm still trying to figure out why I'm not being able to fetch the list of users in my controller.

In Javascript, I tried the following

var _userService = abp.services.app.user;
var allUsers = _userService.getUsers({ Filter : ""});

and then in browser console, I tried to display allUser, it returns a deffered object as shown in the screenshot.....

I also tried

allUsers.done(function(result){
console.log(result);
});

I would like to know how can I fetch the list in javascript

Here is my controller. Please check the '_CreateOrEditKPI' Action

using Abp.AutoMapper;
using Abp.Domain.Repositories;
using PlanQube.Authorization.Users;
using PlanQube.Authorization.Users.Dto;
using PlanQube.Entities;
using PlanQube.Utilities;
using PlanQube.Web.Areas.Mpa.Models.KPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace PlanQube.Web.Areas.Mpa.Controllers
{
    public class KPIController : Controller
    {
        private readonly IRepository<KPI> _KPIRepository;
        private readonly UserAppService _userAppService;
        private readonly UserManager _userManager;

        public KPIController(IRepository<KPI> KPIRepository, UserManager userManager, UserAppService userAppService)// UserAppService userAppService
        {
            _KPIRepository = KPIRepository;
            _userManager = userManager;
            _userAppService = userAppService;
        }

        // GET: Mpa/InitiativeKPI
        public async Task<ActionResult> Index()
        {
            var initiativeKPIs = (await _KPIRepository.GetAllListAsync()).MapTo<List<KPIViewModel>>().ToList();
            return View(initiativeKPIs);
        }

        public PartialViewResult _CreateOrEditKPI(int? id)
        {
            var viewModel = new KPIViewModel();

            if (id.HasValue)
            {
                var output = _KPIRepository.Get((int)id);
                viewModel = new KPIViewModel(output);
            }

            var allUsers = _userManager.Users;
            var allUsers = await _userAppService.GetUsers(new GetUsersInput());
            ViewBag.DdlUsers = new SelectList(allUsers , "Id", "value", null);

            return PartialView("_CreateOrEditKPIModal", viewModel);
        }

    }
}

For the second example, the code would be

public async Task<PartialViewResult> _CreateOrEditKPI(int? id)
        {
            var viewModel = new KPIViewModel();

            if (id.HasValue)
            {
                var output = _KPIRepository.Get((int)id);
                viewModel = new KPIViewModel(output);
            }

            var allUsers = await _userAppService.GetUsers(new GetUsersInput());
            ViewBag.DdlUsers = new SelectList(allUsers , "Id", "value", null);

            return PartialView("_CreateOrEditKPIModal", viewModel);
        }

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 });
    }

<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!

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!

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!

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

Showing 31 to 39 of 39 entries