Ejemplo n.º 1
0
        public async Task <ReviewItemDto> ReviewAsync(ReviewContactDto dto)
        {
            var contactReviewFromDb = await _unitOfWork.GetRepository <ARContactReview>()
                                      .GetAll()
                                      .Where(
                x =>
                x.FK_ReviewUserID == _bysSession.UserId &&
                (x.ARContactReviewDate.GetValueOrDefault().Date == Clock.Now.Date || x.FK_ARContactID == dto.ContactId))
                                      .ToArrayAsync();

            if (contactReviewFromDb.Any(x => x.FK_ARContactID == dto.ContactId))
            {
                throw new BusinessException("Bạn đã đánh giá liên hệ này rồi.");
            }

            if (contactReviewFromDb.Count(x => x.ARContactReviewDate.GetValueOrDefault().Date == Clock.Now.Date) >= 5)
            {
                throw new BusinessException("Bạn đã đánh giá 5 lần trong ngày.");
            }

            if (Clock.Now < contactReviewFromDb.Max(x => x.ARContactReviewDate).GetValueOrDefault().AddMinutes(30))
            {
                throw new BusinessException("Mỗi đánh giá trong ngày phải cách nhau 30 phút.");
            }

            var contactFromDb = await _unitOfWork.GetRepository <ARContact>().GetAll().FirstOrDefaultAsync(x => x.Id == dto.ContactId && x.FK_CreatedUserID == _bysSession.GetUserId());

            if (contactFromDb != null)
            {
                throw new BusinessException("Bạn không thể đánh giá liên hệ do chính mình đóng góp thông tin.");
            }

            var contactReviewToCreate = dto.ToARContactReviewEntity(_bysSession);

            var contactReview = await _unitOfWork.GetRepository <ARContactReview>().InsertAsync(contactReviewToCreate);

            await _unitOfWork.CompleteAsync();

            await UpdateContactEvalution(dto.ContactId);

            await _notificationService.CreateNotificationAsync(
                new CreateNotificationDto
            {
                UserId                 = _bysSession.UserId,
                NotificationType       = NotificationType.AddedContactEvaluation,
                NotificationObjectType = "ARContactReviews",
                NotificationObjectId   = contactReview.Id,
                NotificationContent    = _unitOfWork.GetRepository <ADUser>().Get(_bysSession.UserId)?.ADUserOrganizationName + " đã thêm đánh giá liên hệ " + _unitOfWork.GetRepository <ARContact>().Get(dto.ContactId)?.ARContactName
            });

            return(await GetContactReviewAsync(contactReview.Id));
        }
Ejemplo n.º 2
0
        public async Task <IPagedResultDto <ReviewItemDto> > GetReviewsOfForestPlotAsync(PagingRequestDto pagingRequestDto, int forestPlotId, int actorId)
        {
            var extraData = new ExtraDataReviewsDto
            {
                IsUserReview = await _unitOfWork.GetRepository <APActorReview>()
                               .GetAll()
                               .AnyAsync(x => x.FK_ReviewUserID == _bysSession.GetUserId() && x.FK_ICForestPlotID == forestPlotId)
            };

            return(await _unitOfWork.GetRepository <APActorReview>()
                   .GetAllIncluding(x => x.APActor, x => x.ADUser, x => x.ICForestPlot)
                   .IncludesForToForestPlot(x => x.ICForestPlot)
                   .Where(x => x.FK_ICForestPlotID == forestPlotId && x.APActorReviewIsHide == false && x.FK_APActorID == actorId)
                   .OrderByDescending(x => x.APActorReviewDate)
                   .GetPagedResultAsync(pagingRequestDto.Page, pagingRequestDto.PageSize, x => x.ToReviewItemDto(), extraData));
        }
Ejemplo n.º 3
0
        public async Task <UserDto> CreateUserAsync(CreateUserDto dto)
        {
            CheckDuplicateUser(dto.Email);
            var userDtoToCreate = dto.ToADUserEntity();
            var newUser         = await _userRepository.InsertAsync(userDtoToCreate);

            await _unitOfWork.CompleteAsync();

            if (_bysSession.GetUserId() > 0)
            {
                BackgroundJob.Enqueue(() => SendMailAnnouncePasswordUserAsync(dto.Email));
            }
            else
            {
                BackgroundJob.Enqueue(() => SendMailVerifyUserAsync(dto.Email));
            }

            return(await GetUserAsync(newUser.Id));
        }
Ejemplo n.º 4
0
        public async Task <ContactDto> CreateContactAsync(CreateContactDto dto)
        {
            if (!await ValidateLocationInCharges(dto.LocationInCharges))
            {
                throw new BusinessException("Giá trị không hợp lệ.");
            }

            var contactToCreate = dto.ToARContactEntity(_bysSession.GetUserId());
            var contact         = await _unitOfWork.GetRepository <ARContact>().InsertAsync(contactToCreate);

            foreach (var locationInCharge in dto.LocationInCharges)
            {
                await _unitOfWork.GetRepository <ARContactForestCommuneGroup>()
                .InsertAsync(
                    new ARContactForestCommuneGroup
                {
                    FK_ARContactID       = contact.Id,
                    FK_GECommuneID       = locationInCharge.ForestCommuneID,
                    FK_GEStateProvinceID = locationInCharge.ForestStateProvinceID,
                    FK_GEDistrictID      = locationInCharge.ForestDistrictID
                });
            }

            await _unitOfWork.CompleteAsync();

            await _notificationService.CreateNotificationAsync(
                new CreateNotificationDto
            {
                UserId                 = _bysSession.UserId,
                NotificationType       = NotificationType.AddedContact,
                NotificationObjectType = "ARContacts",
                NotificationObjectId   = contact.Id,
                NotificationContent    = _unitOfWork.GetRepository <ADUser>().Get(_bysSession.UserId)?.ADUserOrganizationName + " đã đóng góp 1 liên hệ " + dto.ContactName
            });

            return(await GetContactAsync(contact.Id));
        }