Example #1
0
        /// <summary>
        /// Gets the user identifier.
        /// </summary>
        /// <param name="appDbContext">The application database context.</param>
        /// <param name="userResolver">The user resolver.</param>
        /// <returns></returns>
        protected int GetUserId(AppDbContext appDbContext, UserResolverService userResolver)
        {
            var id   = userResolver.GetUserId();
            var user = appDbContext.Users.FirstOrDefault(c => c.UserId == id);

            if (user != null)
            {
                return(user.Id);
            }
            user = new User {
                UserId = id
            };
            appDbContext.Users.Add(user);
            appDbContext.SaveChanges();
            return(user.Id);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseService{TModel, TViewModel}"/> class.
 /// </summary>
 /// <param name="mapper">The mapper.</param>
 /// <param name="dataContext">The database context</param>
 /// <param name="userResolver">The user resolver service</param>
 protected BaseService(IMapper mapper, AppDbContext dataContext, UserResolverService userResolver)
 {
     this.mapper      = mapper;
     this.dataContext = dataContext;
     UserId           = GetUserId(dataContext, userResolver);
 }