Пример #1
0
        public EmployeeHelpViewModel(INavigationService navigationService, IMealDataService mealDataService, IUserDataService userDataService)
        {
            _navigationService = navigationService;
            _mealService       = mealDataService;
            _userService       = userDataService;
            Users    = new List <User>();
            Meals    = new List <Meal>();
            ScanMeal = new List <ScannedMeal>();
            ScanUser = new List <ScannedUser>();

            MessagingCenter.Subscribe <NumPadViewModel, List <ScannedMeal> >(this, "sendScannedMeals",
                                                                             (sender, filterdScannedMeals) =>
            {
                this.ScanMeal = filterdScannedMeals;
                GetMealsCommand.Execute(null);
            });


            MessagingCenter.Subscribe <NumPadViewModel, List <ScannedUser> >(this, "sendScannedUsers",
                                                                             (sender, scannedUsers) =>
            {
                //this.ScanUser = scannedUsers;
                GetUserCommand.Execute(null);
            });
        }
Пример #2
0
        public async Task <IActionResult> Edit(GetUserCommand cmd)
        {
            _logger.LogInformation($"接收到请求{HttpContext.Request.Host}{HttpContext.Request.Path},参数 {JsonConvert.SerializeObject(cmd)}");
            var user = await _mediator.Send(cmd, HttpContext.RequestAborted);

            return(View(user));
        }
Пример #3
0
        public void Call_UserService_GetUser_Once()
        {
            var parameters = new List <string>()
            {
                "Fname", "Mname", "Lname"
            };
            var    date               = new DateTime(2018, 12, 12);
            string phone              = "089888888";
            string address            = "test address";
            string town               = "test town";
            var    townServiceMock    = new Mock <ITownService>();
            var    addressServiceMock = new Mock <IAddressService>();
            var    userServiceMock    = new Mock <IUsersServices>();
            var    command            = new GetUserCommand(userServiceMock.Object, addressServiceMock.Object, townServiceMock.Object);

            userServiceMock.Setup(x => x.GetUser(It.IsAny <string>()
                                                 , It.IsAny <string>()
                                                 , It.IsAny <string>()))
            .Returns(new UserViewModel()
            {
                FullName    = parameters[0] + ' ' + parameters[1] + ' ' + parameters[2],
                Phonenumber = phone,
                AddedOn     = date,
                Address     = address,
                Town        = town,
                UserBooks   = new List <UsersBooks>()
            });

            command.Execute(parameters);

            userServiceMock.Verify(s => s.GetUser(parameters[0], parameters[1], parameters[2]), Times.Once());
        }
        /// <summary>
        /// Authorizates user in system
        /// </summary>
        /// <param name="account">Instance of <see cref="AuthRequestApiModel"/> class</param>
        /// <returns>Returns instance of <see cref="AuthResponseApiModel"/> class or null</returns>
        public async Task <AuthResponseApiModel> Auth(AuthRequestApiModel account)
        {
            var dbCommand = new GetUserCommand(dbContext, account.Username);
            var user      = await dbCommand.ExecuteAsync();

            if (user != null)
            {
                var identity = GetIdentity(user);

                if (identity != null)
                {
                    var token = GenerateToken(identity);

                    if (token != null)
                    {
                        var encodedToken = EncodeToken(token);

                        return(new AuthResponseApiModel
                        {
                            AccessToken = encodedToken,
                            Username = identity.Name,
                            Role = user.Role.Name,
                            Email = user.Email
                        });
                    }
                }
            }

            return(null);
        }
Пример #5
0
        /// <summary>
        ///     Controller para que el usuario inicie sesion
        /// </summary>
        /// <param name="loginDTO">Objeto login a ingresar a la aplicaicon</param>
        /// <returns>Objeto tipo Entity con los datos del usuario que se a logeado </returns>
        /// <exception cref="LoginUserNotFoundException">El objeto a retornar es nulo</exception>
        /// <exception cref="DatabaseException">Algun error con la base de datos</exception>

        //POST : /api/Login
        public ActionResult <LoginDTO> Login([FromBody] LoginDTO loginDTO)
        {
            try{
                LoginMapper    LoginMapper = MapperFactory.createLoginMapper();
                Entity         entity      = LoginMapper.CreateEntity(loginDTO);
                GetUserCommand command     = CommandFactory.loginGetUserCommand((Login)entity);
                command.Execute();

                Login answer = command.GetResult();
                if (answer == null)
                {
                    throw new LoginUserNotFoundException("Correo o clave invalido");
                }
                else
                {
                    DTO lDTO = LoginMapper.CreateDTO(answer);
                    return(Ok(lDTO));
                }
            }
            catch (DatabaseException ex) {
                _logger?.LogError(ex, "Database exception cuando se intento iniciar sesion.");
                return(StatusCode(500, ex.Message));
            }
            catch (LoginUserNotFoundException) {
                return(BadRequest(new { message = "Correo o clave invalida." }));
            }
        }
Пример #6
0
        public ICommandResult Handle(GetUserCommand command)
        {
            ICommandResult result = new GetUserCommandResult();

            _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.User, command.RequestHost }, "UserCommandHandler.Handle(Get)");

            try
            {
                if (_userRepository.CheckExists(command.User))
                {
                    User user = _userRepository.Get(command.User);

                    if (user != null)
                    {
                        result = new GetUserCommandResult(200, user.Name, user.Username, user.Groups);
                    }
                }

                else if (_userRepository.Valid)
                {
                    result = new GetUserCommandResult(400, new Notification("User", "Could not be found"));
                }
            }
            catch (Exception e)
            {
                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.User, command.RequestHost }, e);
            }

            return(result);
        }
        public Task <User> Get()
        {
            var command = new GetUserCommand()
            {
                Name = "Vidhya Sagar Reddy"
            };

            return(mediator.Send(command));
        }
Пример #8
0
        public void Confirm()
        {
            string eBayToken = null;
            {
                EbayContext context = new EbayContext(null);
                FetchToken  command = new FetchToken(context);
                command.SessionId = this.SessionId;
                command.Execute();

                eBayToken = command.EbayToken;
            }

            // Get the User's Details
            string userId   = null;
            string siteCode = null;
            {
                EbayContext    context = new EbayContext(eBayToken);
                GetUserCommand command = new GetUserCommand(context);
                command.Execute();

                userId   = command.UserId;
                siteCode = command.SiteCode;
            }

            Account account = new Account()
            {
                EbayToken = eBayToken,
                UserId    = userId,
                SiteCode  = siteCode
            };

            // Get the Account's related Site Details
            {
                PopulateSitesJob job  = new PopulateSitesJob();
                Site             site = job.PopulateSite(this.Context.Sites, account);
                account.Site = site;
            }

            // Set the Accounts Alert Preferences
            // TODO: Need to try catch this.
            {
                UpdatePreferencesJob job = new UpdatePreferencesJob();
                job.Execute(account, this.Context.AlertPreferences);
            }

            // Save the account
            {
                this.Context.Accounts.Add(account);
                AccountsFactory factory = new AccountsFactory();
                factory.Save(this.Context.Accounts);

                ObservableCollection <Account> newAccounts = factory.Load();
            }

            this.Result = "Account Added";
        }
Пример #9
0
        public async Task <IQueryable <UserQuery> > Handle(GetUserCommand request, CancellationToken cancellationToken)
        {
            #region Persistence

            var contragentsDomain = await _UserRepository.Get(request.GraphFilters);

            var response = contragentsDomain.Select(item =>
                                                    item.ToQueryModel <UserQuery>(_Mapper));

            #endregion

            return(response);
        }
Пример #10
0
        public void Throw_If_ParamethersCount_IsInvalid()
        {
            var parameters = new List <string>()
            {
                "Fname", "Mname"
            };
            var townServiceMock    = new Mock <ITownService>();
            var addressServiceMock = new Mock <IAddressService>();
            var userServiceMock    = new Mock <IUsersServices>();
            var command            = new GetUserCommand(userServiceMock.Object, addressServiceMock.Object, townServiceMock.Object);

            command.Execute(parameters);
        }
Пример #11
0
        public async Task <CommandResult> GetUser([FromServices] GetUserCommand _getUserCommand)
        {
            var userInput = new UserInput <string>
            {
                Data   = string.Empty,
                UserId = User.GetUserId()
            };

            var result = await
                         Business.InvokeAsync <GetUserCommand, UserInput <string>, CommandResult <GetUserResult> >(_getUserCommand,
                                                                                                                   userInput).ConfigureAwait(false);

            return(result);
        }
Пример #12
0
        public async Task <IEnumerable <Infrastructure.Database.Query.Model.User> > GetUsers(
            Dictionary <string, GraphFilter> filters,
            [Service] IServiceProvider serviceProvider,
            CancellationToken cancellationToken)
        {
            var getUserCommand = new GetUserCommand
            {
                GraphFilters = filters
            };

            using (var scope = serviceProvider.CreateScope())
            {
                var mediator = scope.ServiceProvider.GetRequiredService <IMediator>();
                return((await mediator.Send(getUserCommand, cancellationToken)).ToList());
            }
        }
Пример #13
0
        public GetUserCommandResult Get(Guid id)
        {
            GetUserCommand command = new GetUserCommand()
            {
                User = id
            };

            command.setRequestHost(HttpContext.Request.Host.ToString());

            _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { User = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method });

            GetUserCommandResult result = (GetUserCommandResult)_userHandler.Handle(command);

            _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { User = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method, Code = this.Response.StatusCode });

            HttpContext.Response.StatusCode = result.Code;

            return(result);
        }
        public async Task GetUserCommandHandlerShouldReturnUserObject()
        {
            var user = new User()
            {
                Password = "******",
                Username = "******"
            };

            var userCommand = new GetUserCommand(user);

            var listUser = new List <User> {
                user
            };

            var handler = new GetUserCommandHandler(_userRepositoryMock.Object);

            _userRepositoryMock.Setup(a => a.Search(a => a.Username == userCommand.User.Username && a.Password == userCommand.User.Password)).ReturnsAsync(listUser);

            var result = await handler.Handle(userCommand, new CancellationToken());

            result.Should().BeOfType <User>();
        }
Пример #15
0
        public async Task <Result <UserDto> > Handle(GetUserCommand request, CancellationToken cancellationToken)
        {
            var cacheKey = $"User-{request.Id}";
            var cache    = await _cacheService.GetStringAsync(cacheKey);

            UserDto user;

            if (cache.TryGetValue <User>(out var cachedUser))
            {
                user = _mapper.Map <UserDto>(cachedUser);

                return(Result <UserDto> .Success(user));
            }

            var userInDb = await _userRepository.GetAsync(u => u.Id == request.Id);

            userInDb.CheckForNull();
            await _cacheService.SetCacheAsync(cacheKey, userInDb, _userSettings);

            user = _mapper.Map <UserDto>(userInDb);

            return(Result <UserDto> .Success(user));
        }
Пример #16
0
        public void Return_SuccessMessage()
        {
            var parameters = new List <string>()
            {
                "Fname", "Mname", "Lname"
            };
            var    fullName           = parameters[0] + ' ' + parameters[1] + ' ' + parameters[2];
            var    date               = new DateTime(2018, 12, 12);
            string phone              = "089888888";
            string address            = "test address";
            string town               = "test town";
            var    townServiceMock    = new Mock <ITownService>();
            var    addressServiceMock = new Mock <IAddressService>();
            var    userServiceMock    = new Mock <IUsersServices>();
            var    command            = new GetUserCommand(userServiceMock.Object, addressServiceMock.Object, townServiceMock.Object);

            userServiceMock.Setup(x => x.GetUser(It.IsAny <string>()
                                                 , It.IsAny <string>()
                                                 , It.IsAny <string>()))
            .Returns(new UserViewModel()
            {
                FullName    = parameters[0] + ' ' + parameters[1] + ' ' + parameters[2],
                Phonenumber = phone,
                AddedOn     = date,
                Address     = address,
                Town        = town,
                UserBooks   = new List <UsersBooks>()
            });

            var message = command.Execute(parameters);

            StringAssert.Contains(message, fullName);
            StringAssert.Contains(message, phone);
            StringAssert.Contains(message, date.ToString());
            StringAssert.Contains(message, address);
            StringAssert.Contains(message, town);
        }
 private void CompareGetUserCommand(GetUserCommand c, GetUserCommand dc)
 {
 }
 public async Task <IActionResult> GetAsync([FromRoute] GetUserCommand command, long id)
 {
     command.Id = id;
     return(GetResponse(await GetUserHandler.ExecuteActionAsync(command)));
 }
 private void CompareGetUserCommand(GetUserCommand c, GetUserCommand dc)
 {
 }
 private void CompareGetUserCommand(GetUserCommand c, GetUserCommand dc)
 {
     Assert.AreEqual(c.CommandName, dc.CommandName);
 }
 private void CompareGetUserCommand(GetUserCommand c, GetUserCommand dc)
 {
     Assert.AreEqual(c.CommandName, dc.CommandName);
 }
Пример #22
0
        public User GetUserById(int userId)
        {
            var command = new GetUserCommand(_scopeFactory);

            return(command.Execute(userId));
        }