示例#1
0
        public async Task <Guid> InsertLoanApplicationTaskUser(Data.Context.Application application, Guid userId, RoleEnum role, ApplicationStatusEnum status, string instanceId = null)
        {
            try
            {
                var currentApplication = await _baseLogic.Of <Data.Context.Application>().Base()
                                         .FirstOrDefaultAsync(a => a.Id == application.Id);

                currentApplication.Status = status;
                await _baseLogic.Of <Data.Context.Application>().Update(currentApplication);

                var planEndDate = await GetPlanedEndDatetime(application.Id, status);

                var _role = await _baseLogic.Of <Role>().GetQueryable(x => !x.IsDeleted && x.Value == role).Select(x => x.Id)
                            .FirstOrDefaultAsync();

                var result = await _baseLogic.Of <Data.Context.ApplicationTask>().Add(
                    new Data.Context.ApplicationTask
                {
                    ApplicationId   = application.Id,
                    UserId          = userId,
                    RoleId          = _role,
                    AppointmentDate = DateTime.Now,
                    PlanEndDate     = planEndDate,
                    Status          = status
                });

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
示例#2
0
        public async Task <object> Login(LoginInDto dto)
        {
            var user = await _baseLogic.Of <User>()
                       .GetQueryable(x => x.Login == dto.Login && !x.IsDeleted)
                       .Include(x => x.UserRoles)
                       .ThenInclude(x => x.Role)
                       .FirstOrDefaultAsync();

            if (user == default)
            {
                throw new ArgumentException("Пользователь не найден");
            }

            if (user.IsBlocked)
            {
                throw new ArgumentException("Пользователь заблокирован, обратитесь к администратору");
            }

            var pwdhash = HashPwd(dto.Password);

            if (user.Password != pwdhash)
            {
                user.PasswordTryCount++;
                if (user.PasswordTryCount >= 5)
                {
                    user.IsBlocked = true;
                }
                await _baseLogic.Of <User>().Update(user);

                throw new ArgumentException("Вами введен некорректный пароль. Введите пароль еще раз");
            }

            // сброс пароля
            user.PasswordTryCount = 0;
            user.LastInviteDate   = DateTime.Now;


            var accessToken  = _identityLogic.GenerateAccessToken(user);
            var refreshToken = _identityLogic.GenerateRefreshToken(user);

            user.RefreshToken = refreshToken;
            await _baseLogic.Of <User>().Update(user);

            return(new
            {
                accessToken,
                refreshToken
            });
        }
示例#3
0
        public async Task <IActionResult> GetExpiredContractors()
        {
            try
            {
                var userIds = await _baseLogic.Of <UserRole>().GetQueryable(a => a.Role.Value == RoleEnum.Counterparty)
                              .Include(a => a.Role)
                              .Select(a => a.UserId).ToListAsync();

                var tmpAll = await _baseLogic.Of <ApplicationTask>()
                             .GetQueryable(a => userIds.Any(t => t.Equals(a.UserId)))
                             .GroupBy(a => a.ApplicationId).Select(a => new
                {
                    a.Key,
                    Count = a.Count()
                }).ToListAsync();

                var tmpExpired = await _baseLogic.Of <ApplicationTask>()
                                 .GetQueryable(a => userIds.Any(t => t == a.UserId) && a.PlanEndDate > DateTime.Now)
                                 .GroupBy(a => a.ApplicationId).Select(a => new
                {
                    a.Key,
                    Count = a.Count()
                }).ToListAsync();

                var data = await _baseLogic.Of <DicContractors>().Base().ToListAsync();

                var result = data.AsEnumerable().Select(a =>
                                                        new
                {
                    Name    = a.NameRu,
                    All     = tmpAll.Where(t => t.Key == a.Id).SingleOrDefault().Count,
                    Expired = tmpExpired.Where(t => t.Key == a.Id).SingleOrDefault().Count
                }
                                                        );
                return(Ok(result));
            }
            catch (Exception e)
            {
                return(ExceptionResult(e));
            }
        }
示例#4
0
        public async Task <object> GetClientNotifications(Guid ClientId)
        {
            var NotificationClient = await _baseLogic.Of <Notification>().GetQueryable(x => !x.IsDeleted)
                                     .Include(x => x.LoanApplication).ThenInclude(x => x.User)
                                     .Where(x => x.LoanApplication.UserId == ClientId)
                                     .Select(x => new
            {
                x.LoanApplication.User.FullName,
                x.LoanApplication.Number,
                x.TaskCode,
                applicationId = x.ApplicationId,
                x.SubjectKz,
                x.SubjectRu,
                x.BodyKz,
                x.BodyRu,
                createdDate = x.CreatedDate.ToString("G")
            })
                                     .ToListAsync();

            return(NotificationClient);
        }
示例#5
0
        public async Task <TTSFile> UploadFile(string fileName, byte[] fileBytes)
        {
            fileName = NormalizeName(fileName);
            GeneratePath(fileName, out string filePath);
            System.IO.File.WriteAllBytes(filePath, fileBytes);

            TTSFile file = new TTSFile()
            {
                Name        = fileName,
                Size        = fileBytes.Length,
                Path        = filePath,
                ContentType = ContentTypeHelper.GetContentType(Path.GetExtension(fileName)),
            };

            await _iBaseLogic.Of <TTSFile>().Add(file);

            return(file);
        }
示例#6
0
        public async Task <Guid> InsertOrUpdateApplication(ApplicationInDto model, Guid userId)
        {
            var actions = new List <Action <ApplicationInDto, Data.Context.Application> >();

            actions.Add((dto, ent) => ent.UserId = dto.UserId ?? userId);
            if (model.Id != null && model.Id != Guid.Empty)
            {
                await UpdateEndDateTime(model, userId);

                var application = await _baseLogic.Of <Data.Context.Application>().Base().FirstOrDefaultAsync(a => a.Id == model.Id);

                _ = _baseLogic.Of <Data.Context.Application>().Update(model.MapTo(application, actions));
                return(application.Id);
            }
            actions.Add((dto, ent) => ent.Status = ApplicationStatusEnum.Draft);
            var tmp = await _baseLogic.Of <Data.Context.Application>()
                      .Add(model.CreateMappedObject(actions));

            await GenerateRegNumber(tmp);

            await _applicationWorkflowLogic.CreateApplication(tmp, userId);

            return(tmp);
        }
        protected async Task <RoleEnum?> GetRoleByUserId(Guid userId)
        {
            var roles = await _baseLogic.Of <Shared.Data.Context.User>().Base().Include(a => a.UserRoles).ThenInclude(a => a.Role).FirstOrDefaultAsync(a => a.Id == userId);

            return(roles.Roles.FirstOrDefault()?.Value);
        }
示例#8
0
        public async Task <object> UserRoles(Guid userId)
        {
            var _ = await _baseLogic.Of <UserRole>().GetQueryable(x => !x.IsDeleted && x.UserId == userId)
                    .AsNoTracking()
                    .Include(x => x.Role)
                    .Select(x => new
            {
                x.Id,
                x.Role.Value
            })
                    .ToListAsync();

            return(_);
        }