Ejemplo n.º 1
0
        public override async Task <UserRemoveReply> Remove(UserInformationRequest request, ServerCallContext context)
        {
            var appUser = await _userManager.FindByIdAsync(request.UserId);

            if (appUser == null)
            {
                return new UserRemoveReply
                       {
                           Success = false
                       }
            }
            ;

            try
            {
                await _userManager.DeleteAsync(appUser);
            }
            catch (Exception e)
            {
                _logger.LogInformation("error occured while deleting user {0}. exception: {1}", appUser.Id, e.Message);
                return(new UserRemoveReply
                {
                    Success = false
                });
            }

            _logger.LogInformation("User {0} successfully were removed", request.UserId);

            return(new UserRemoveReply
            {
                Success = true
            });
        }
    }
Ejemplo n.º 2
0
        public override async Task <UserInformationReply> Get(UserInformationRequest request, ServerCallContext context)
        {
            _logger.LogInformation("Get user details of {0}", request.UserId);
            var user = await _userManager.FindByIdAsync(request.UserId);

            if (user == null)
            {
                return new UserInformationReply
                       {
                           Email        = "user.Email",
                           Enable       = true,
                           Username     = "******",
                           FirstName    = "user.FirstName",
                           LastName     = "user.LastName",
                           NationalCode = "user.NationalCode",
                           PhoneNumber  = "user.PhoneNumber"
                       }
            }
            ;
            return(new UserInformationReply
            {
                Email = user.Email ?? "",
                Enable = user.Enable,
                Username = user.UserName ?? "",
                FirstName = user.FirstName ?? "",
                LastName = user.LastName ?? "",
                NationalCode = user.NationalCode ?? "",
                PhoneNumber = user.PhoneNumber ?? ""
            });
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Information([FromBody] UserInformationRequest apiRequest)
        {
            try
            {
                if (apiRequest == null)
                {
                    return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "Empty required fields", null)));
                }

                if (string.IsNullOrEmpty(apiRequest.UserID))
                {
                    return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "UserID is required", null)));
                }

                var result = (await RespositoryService.UserService.GetUserInfo(apiRequest)).ResponseObject;
                if (result == null)
                {
                    return(Ok(new ResultDetail(ErrorConstants.Unknown, "User not found", Version, result)));
                }

                var response = new ResultDetail(ErrorConstants.Success, "Success", Version, result);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                throw new AppHttpException(HttpStatusCode.OK
                                           , new ResultDetail(ErrorConstants.Unknown, ex.Message, Version));
            }
        }
Ejemplo n.º 4
0
        public async Task <UserDto> GetUserInfo(UserInformationRequest request)
        {
            using (var dbContext = await MySqlServerRepository.OpenConnection())
            {
                var sql = @"SELECT * FROM user 
                            WHERE user.id = @UserID";

                var result = (await dbContext.QueryAsync <UserDto>(sql, new { @UserID = request.UserID })).FirstOrDefault();
                return(result);
            }
        }
Ejemplo n.º 5
0
        public UserInformationResponse GetUserInformation(UserInformationRequest request, long userId, dbDataContext db)
        {
            var user = GetUserDetails(userId, db);

            int month = 0;

            if (request == null || request.Month == null)
            {
                month = DateTime.Today.Month;
            }
            else
            {
                month = request.Month.Value;
            }

            //var today = DateTime.Today; // new DateTime(2017, 8, 1).Date;
            var startDate = new DateTime(DateTime.Today.Year, month, 1);

            int daysInMonth = 0;

            if (month == DateTime.Today.Month)
            {
                daysInMonth = DateTime.Today.Day;
            }
            else
            {
                daysInMonth = DateTime.DaysInMonth(DateTime.Today.Year, month);
            }

            var endDate = new DateTime(DateTime.Today.Year, month, daysInMonth);

            var decryptedSystemPassword = PasswordEncryptor.Decrypt(user.SystemPassword);
            var decryptedSystemNumber   = PasswordEncryptor.Decrypt(user.SystemNumber);

            var loginParameters = new HappyHoursLoginParameters()
            {
                Credentials = new HappyHoursCredentials()
                {
                    Username = user.SystemEmail,
                    Password = decryptedSystemPassword,
                    Number   = decryptedSystemNumber
                },
                StartDate = startDate,
                EndDate   = endDate //today // new DateTime(2017, 8, 31).Date
            };

            HappyHoursCoreBL manager       = new HappyHoursCoreBL();
            HappyHourSummary summaryResult = manager.GetSummary(loginParameters);

            IList <MonthDetails> months    = new List <MonthDetails>();
            CultureInfo          usEnglish = new CultureInfo("en-US");

            for (var i = 1; i <= DateTime.Today.Month; i++)
            {
                months.Add(new MonthDetails()
                {
                    Month = i,
                    Name  = usEnglish.DateTimeFormat.GetMonthName(i)
                });
            }

            return(new UserInformationResponse()
            {
                FirstName = user.FirstName,
                LastName = user.LastName,
                ExtraMinutes = summaryResult.ExtraMinutes,
                LackMinutes = summaryResult.LackMinutes,
                Days = summaryResult.DayDetails.Select(c => new DayTimeDetails()
                {
                    ExtraMinutes = c.ExtraMinutes,
                    LackMinutes = c.LackMinutes,
                    Date = HappyHourTimestampProvider.GetDateTimestamp(c.Date),
                    StartTime = HappyHourTimestampProvider.GetDateTimeTimestamp(c.StartTime),
                    EndTime = HappyHourTimestampProvider.GetDateTimeTimestamp(c.EndTime),
                    Day = c.Day
                }).ToList(),
                Months = months
            });
        }
Ejemplo n.º 6
0
        public async Task <ServiceResponse <UserDto> > GetUserInfo(UserInformationRequest request)
        {
            var result = await _repository.GetUserInfo(request);

            return(new ServiceResponse <UserDto>(result, string.Empty, "success", false));
        }
        public UserInformationResponse Index(UserInformationRequest request)
        {
            var userId = GetUserId();

            return(BL.GetUserInformation(request, userId, db));
        }