示例#1
0
        public ActionResult <UserInfoViewModel> GetUserInfo(string email)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                return(ActionResult <UserInfoViewModel>
                       .CreateFailure(ex : new ArgumentNullException(),
                                      statusCode : System.Net.HttpStatusCode.BadRequest));
            }

            var user = _userRepository.GetByEmail(email);

            if (user == null)
            {
                return(ActionResult <UserInfoViewModel>
                       .CreateFailure(ex : new ArgumentNullException(),
                                      statusCode : System.Net.HttpStatusCode.NotFound));
            }

            var userInfoViewModel = _mapper.Map <User, UserInfoViewModel>(user);

            userInfoViewModel.Phones = user.Phones.Select(ph => new PhoneViewModel
            {
                AreaCode    = ph.AreaCode,
                CountryCode = ph.CountryCode,
                Number      = ph.Number
            }).ToList();

            return(ActionResult <UserInfoViewModel>
                   .CreateSuccessResult(result : userInfoViewModel));
        }
示例#2
0
        public static async Task <ActionResult> Initialise(IConfiguration configuration)
        {
            try
            {
                Logger = new ConsoleLogger();

                IMapper mapper = Mapper.CreateAndInitialiseMappings(Logger);

                ActionResult createPersistorResult = CreatePersistor(configuration, out IPersistor persistor);

                if (!createPersistorResult.IsSuccess)
                {
                    return(createPersistorResult);
                }

                var accountingDataAccess = new AccountingDataAccess(persistor, Logger);
                var accountingEngine     = new AccountingEngine(accountingDataAccess, Logger);

                AccountingManager = new AccountingManager(
                    accountingEngine,
                    accountingDataAccess,
                    mapper,
                    Logger);

                return(await AccountingManager.Initialise());
            }
            catch (Exception ex)
            {
                var message = $"Unhandled exception: \"{ex.Message}\".";

                Logger?.LogError(message, ex);

                return(ActionResult.CreateFailure(message));
            }
        }
示例#3
0
        public ActionResult <UserViewModel> Authenticate(AuthViewModel authViewModel)
        {
            _authValidationServices.Validate(authViewModel);

            var user = _userRepository.GetByEmailAndPassword(authViewModel.Email, authViewModel.Password);

            if (user == null)
            {
                return(ActionResult <UserViewModel> .CreateFailure(ex : new UnauthorizedAccessException(), statusCode : System.Net.HttpStatusCode.Unauthorized));
            }

            var userViewModel = _mapper.Map <User, UserViewModel>(user);

            userViewModel.Phones = user.Phones.Select(ph => new PhoneViewModel
            {
                AreaCode    = ph.AreaCode,
                CountryCode = ph.CountryCode,
                Number      = ph.Number
            }).ToList();

            /// Update LastAccess.
            _userService.UpdateInfoAccess(userViewModel);

            /// Create Token.
            userViewModel.Token = CreateToken(userViewModel);

            return(ActionResult <UserViewModel> .CreateSuccessResult(result : userViewModel, message : "User successfully logged in!"));
        }
        public async Task <ActionResult> UpdateLastPeriodEndDate(DateTime newEnd)
        {
            GetResult <Period> getLastPeriodResult = await GetLastPeriod();

            if (!getLastPeriodResult.IsSuccess)
            {
                return(ActionResult.CreateFailure("Failed to retrieve last period"));
            }

            Period oldLastPeriod = getLastPeriodResult.Result;

            var newLastPeriod = new Period(
                oldLastPeriod.Start,
                newEnd);

            _periods.Remove(oldLastPeriod);
            _periods.Add(newLastPeriod);

            return(await _persistor.Persist());
        }