コード例 #1
0
        public async Task <SLAPolicy> Update(SLAPolicy SLAPolicy)
        {
            if (!await SLAPolicyValidator.Update(SLAPolicy))
            {
                return(SLAPolicy);
            }
            try
            {
                var oldData = await UOW.SLAPolicyRepository.Get(SLAPolicy.Id);

                await UOW.Begin();

                await UOW.SLAPolicyRepository.Update(SLAPolicy);

                await UOW.Commit();

                SLAPolicy = await UOW.SLAPolicyRepository.Get(SLAPolicy.Id);

                await Logging.CreateAuditLog(SLAPolicy, oldData, nameof(SLAPolicyService));

                return(SLAPolicy);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(SLAPolicyService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(SLAPolicyService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #2
0
        public async Task <Position> Update(Position Position)
        {
            if (!await PositionValidator.Update(Position))
            {
                return(Position);
            }
            try
            {
                var oldData = await UOW.PositionRepository.Get(Position.Id);

                await UOW.Begin();

                await UOW.PositionRepository.Update(Position);

                await UOW.Commit();

                Position = await UOW.PositionRepository.Get(Position.Id);

                await Logging.CreateAuditLog(Position, oldData, nameof(PositionService));

                return(Position);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(PositionService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(PositionService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #3
0
        public async Task <SmsQueueStatus> Update(SmsQueueStatus SmsQueueStatus)
        {
            if (!await SmsQueueStatusValidator.Update(SmsQueueStatus))
            {
                return(SmsQueueStatus);
            }
            try
            {
                var oldData = await UOW.SmsQueueStatusRepository.Get(SmsQueueStatus.Id);

                await UOW.Begin();

                await UOW.SmsQueueStatusRepository.Update(SmsQueueStatus);

                await UOW.Commit();

                SmsQueueStatus = await UOW.SmsQueueStatusRepository.Get(SmsQueueStatus.Id);

                await Logging.CreateAuditLog(SmsQueueStatus, oldData, nameof(SmsQueueStatusService));

                return(SmsQueueStatus);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(SmsQueueStatusService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(SmsQueueStatusService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #4
0
        public async Task <ContractPaymentHistory> Update(ContractPaymentHistory ContractPaymentHistory)
        {
            if (!await ContractPaymentHistoryValidator.Update(ContractPaymentHistory))
            {
                return(ContractPaymentHistory);
            }
            try
            {
                var oldData = await UOW.ContractPaymentHistoryRepository.Get(ContractPaymentHistory.Id);

                await UOW.Begin();

                await UOW.ContractPaymentHistoryRepository.Update(ContractPaymentHistory);

                await UOW.Commit();

                ContractPaymentHistory = await UOW.ContractPaymentHistoryRepository.Get(ContractPaymentHistory.Id);

                await Logging.CreateAuditLog(ContractPaymentHistory, oldData, nameof(ContractPaymentHistoryService));

                return(ContractPaymentHistory);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(ContractPaymentHistoryService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(ContractPaymentHistoryService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #5
0
        public async Task <KpiItemContent> Update(KpiItemContent KpiItemContent)
        {
            if (!await KpiItemContentValidator.Update(KpiItemContent))
            {
                return(KpiItemContent);
            }
            try
            {
                var oldData = await UOW.KpiItemContentRepository.Get(KpiItemContent.Id);

                await UOW.Begin();

                await UOW.KpiItemContentRepository.Update(KpiItemContent);

                await UOW.Commit();

                KpiItemContent = await UOW.KpiItemContentRepository.Get(KpiItemContent.Id);

                await Logging.CreateAuditLog(KpiItemContent, oldData, nameof(KpiItemContentService));

                return(KpiItemContent);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(KpiItemContentService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(KpiItemContentService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #6
0
        public async Task <TicketSource> Update(TicketSource TicketSource)
        {
            if (!await TicketSourceValidator.Update(TicketSource))
            {
                return(TicketSource);
            }
            try
            {
                var oldData = await UOW.TicketSourceRepository.Get(TicketSource.Id);

                await UOW.Begin();

                await UOW.TicketSourceRepository.Update(TicketSource);

                await UOW.Commit();

                TicketSource = await UOW.TicketSourceRepository.Get(TicketSource.Id);

                await Logging.CreateAuditLog(TicketSource, oldData, nameof(TicketSourceService));

                return(TicketSource);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(TicketSourceService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(TicketSourceService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #7
0
        public async Task <OrderQuote> Update(OrderQuote OrderQuote)
        {
            if (!await OrderQuoteValidator.Update(OrderQuote))
            {
                return(OrderQuote);
            }
            try
            {
                var oldData = await UOW.OrderQuoteRepository.Get(OrderQuote.Id);

                await UOW.Begin();

                await UOW.OrderQuoteRepository.Update(OrderQuote);

                await UOW.Commit();

                OrderQuote = await UOW.OrderQuoteRepository.Get(OrderQuote.Id);

                await Logging.CreateAuditLog(OrderQuote, oldData, nameof(OrderQuoteService));

                return(OrderQuote);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(OrderQuoteService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(OrderQuoteService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #8
0
        public async Task <KnowledgeGroup> Update(KnowledgeGroup KnowledgeGroup)
        {
            if (!await KnowledgeGroupValidator.Update(KnowledgeGroup))
            {
                return(KnowledgeGroup);
            }
            try
            {
                var oldData = await UOW.KnowledgeGroupRepository.Get(KnowledgeGroup.Id);

                await UOW.Begin();

                await UOW.KnowledgeGroupRepository.Update(KnowledgeGroup);

                await UOW.Commit();

                KnowledgeGroup = await UOW.KnowledgeGroupRepository.Get(KnowledgeGroup.Id);

                await Logging.CreateAuditLog(KnowledgeGroup, oldData, nameof(KnowledgeGroupService));

                return(KnowledgeGroup);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(KnowledgeGroupService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(KnowledgeGroupService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #9
0
        public async Task <User> ChangePassword(User user, string newPassword)
        {
            if (!await UserValidator.Update(user, newPassword))
            {
                return(user);
            }

            using (UnitOfWork.Begin())
            {
                try
                {
                    UserFilter filter = new UserFilter
                    {
                        Username = user.Username,
                        Password = user.Password
                    };
                    user = await Get(filter);

                    user.Password = newPassword;

                    await UnitOfWork.UserRepository.Update(user);

                    await UnitOfWork.Commit();

                    return(await Get(new UserFilter
                    {
                        Username = user.Username,
                        Password = newPassword
                    }));
                }
                catch (Exception e)
                {
                    await UnitOfWork.Rollback();

                    user.AddError(nameof(UserService), nameof(ChangePassword), CommonEnum.ErrorCode.SystemError);
                    return(user);
                }
            }
        }
コード例 #10
0
        public async Task <University_Majors_SubjectGroup> Create(University_Majors_SubjectGroup university_Majors_SubjectGroup)
        {
            if (!await University_Majors_SubjectGroupValidator.Create(university_Majors_SubjectGroup))
            {
                return(university_Majors_SubjectGroup);
            }
            try
            {
                await UOW.Begin();

                await UOW.University_Majors_SubjectGroupRepository.Create(university_Majors_SubjectGroup);

                await UOW.Commit();

                return(await Get(university_Majors_SubjectGroup.Id));
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                throw new MessageException(ex);
            }
        }
コード例 #11
0
ファイル: AppUserService.cs プロジェクト: hienmx95/crm-be
        public async Task <AppUser> UpdateRole(AppUser AppUser)
        {
            try
            {
                var oldData = await UOW.AppUserRepository.Get(AppUser.Id);

                oldData.AppUserRoleMappings = AppUser.AppUserRoleMappings;
                await UOW.Begin();

                await UOW.AppUserRepository.Update(oldData);

                await UOW.Commit();

                var newData = await UOW.AppUserRepository.Get(AppUser.Id);

                await Logging.CreateAuditLog(newData, oldData, nameof(AppUserService));

                return(newData);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(AppUserService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(AppUserService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #12
0
        public async Task <WorkflowDefinition> Create(WorkflowDefinition WorkflowDefinition)
        {
            if (!await WorkflowDefinitionValidator.Create(WorkflowDefinition))
            {
                return(WorkflowDefinition);
            }

            try
            {
                await UOW.Begin();

                InitParameter(WorkflowDefinition);
                WorkflowDefinition.CreatorId = CurrentContext.UserId;
                await UOW.WorkflowDefinitionRepository.Create(WorkflowDefinition);

                await UOW.Commit();

                await Logging.CreateAuditLog(WorkflowDefinition, new { }, nameof(WorkflowDefinitionService));

                return(await UOW.WorkflowDefinitionRepository.Get(WorkflowDefinition.Id));
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                await Logging.CreateSystemLog(ex.InnerException, nameof(WorkflowDefinitionService));

                if (ex.InnerException == null)
                {
                    throw new MessageException(ex);
                }
                else
                {
                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #13
0
        public async Task <SubjectGroup> Create(SubjectGroup subjectGroup)
        {
            if (!await SubjectGroupValidator.Create(subjectGroup))
            {
                return(subjectGroup);
            }

            try
            {
                await UOW.Begin();

                await UOW.SubjectGroupRepository.Create(subjectGroup);

                await UOW.Commit();

                return(await Get(subjectGroup.Id));
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                throw new MessageException(ex);
            }
        }
コード例 #14
0
        public async Task <University> Create(University university)
        {
            if (!await UniversityValidator.Create(university))
            {
                return(university);
            }

            try
            {
                await UOW.Begin();

                await UOW.UniversityRepository.Create(university);

                await UOW.Commit();

                return(await Get(university.Id));
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                throw new MessageException(ex);
            }
        }
コード例 #15
0
        public async Task <Majors> Create(Majors majors)
        {
            if (!await MajorsValidator.Create(majors))
            {
                return(majors);
            }

            try
            {
                await UOW.Begin();

                await UOW.MajorsRepository.Create(majors);

                await UOW.Commit();

                return(await Get(majors.Id));
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                throw new MessageException(ex);
            }
        }
コード例 #16
0
ファイル: KpiGeneralService.cs プロジェクト: hienmx95/crm-be
        public async Task <KpiGeneral> Create(KpiGeneral KpiGeneral)
        {
            if (!await KpiGeneralValidator.Create(KpiGeneral))
            {
                return(KpiGeneral);
            }

            try
            {
                await UOW.Begin();

                List <KpiGeneral> KpiGenerals = new List <KpiGeneral>();
                if (KpiGeneral.EmployeeIds != null && KpiGeneral.EmployeeIds.Any())
                {
                    foreach (var EmployeeId in KpiGeneral.EmployeeIds)
                    {
                        var newObj = Utils.Clone(KpiGeneral);
                        newObj.EmployeeId = EmployeeId;
                        newObj.CreatorId  = CurrentContext.UserId;
                        newObj.RowId      = Guid.NewGuid();
                        KpiGenerals.Add(newObj);
                    }
                }
                await UOW.KpiGeneralRepository.BulkMerge(KpiGenerals);

                await UOW.Commit();

                await Logging.CreateAuditLog(KpiGeneral, new { }, nameof(KpiGeneralService));

                return(KpiGeneral);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(KpiGeneralService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(KpiGeneralService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #17
0
        public async Task <ExamRoomExamPeriod> Delete(ExamRoomExamPeriod examRoomExamPeriod)
        {
            using (UOW.Begin())
            {
                try
                {
                    await UOW.ExamRoomExamPeriodRepository.Delete(examRoomExamPeriod.ExamRoomId, examRoomExamPeriod.ExamPeriodId);

                    await UOW.Commit();
                }
                catch (Exception e)
                {
                    await UOW.Rollback();

                    examRoomExamPeriod.AddError(nameof(ExamRoomExamPeriodService), nameof(Delete), CommonEnum.ErrorCode.SystemError);
                }
            }
            return(examRoomExamPeriod);
        }
コード例 #18
0
        public async Task <TicketGeneratedId> UpdateUsed(long Id)
        {
            try
            {
                var oldData = await UOW.TicketGeneratedIdRepository.Get(Id);

                if (oldData != null)
                {
                    oldData.Used = true;
                }
                await UOW.Begin();

                await UOW.TicketGeneratedIdRepository.Update(oldData);

                await UOW.Commit();

                var TicketGeneratedId = await UOW.TicketGeneratedIdRepository.Get(Id);

                await Logging.CreateAuditLog(TicketGeneratedId, oldData, nameof(TicketGeneratedIdService));

                return(TicketGeneratedId);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(TicketGeneratedIdService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(TicketGeneratedIdService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #19
0
        public async Task <Store> RemoveFromCustomer(Store Store)
        {
            try
            {
                var oldData = await UOW.StoreRepository.Get(Store.Id);

                Store.CustomerId = null;
                await UOW.Begin();

                await UOW.StoreRepository.BulkMerge(new List <Store> {
                    Store
                });

                await UOW.Commit();

                Store = await UOW.StoreRepository.Get(Store.Id);

                await Logging.CreateAuditLog(Store, oldData, nameof(StoreService));

                return(Store);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(StoreService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(StoreService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #20
0
        public async Task <Student> Register(Student student)
        {
            if (!await StudentValidator.Create(student))
            {
                return(student);
            }

            try
            {
                await UOW.Begin();

                student.Id = Guid.NewGuid();
                await UOW.StudentRepository.Create(student);

                User user = new User()
                {
                    Username  = student.Identify,
                    Id        = Guid.NewGuid(),
                    Password  = CryptographyExtentions.GeneratePassword(),
                    IsAdmin   = false,
                    StudentId = student.Id,
                    Email     = student.Email
                };
                await UOW.UserRepository.Create(user);

                await UOW.Commit();

                var Mail = new Mail();
                Mail.Recipients = new List <string> {
                    user.Email
                };
                Mail.Subject = "Tạo tài khoản TF";
                Mail.Body    = $"Tài khoản của bạn đã được tạo. Username: {user.Username} Password: {user.Password}";
                Thread sendMailThread = new Thread(() => MailService.Send(Mail));
                sendMailThread.Start();
                return(await UOW.StudentRepository.Get(student.Id));
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                throw new MessageException(ex);
            }
        }
コード例 #21
0
        public async Task <Student> Register(Student student)
        {
            if (!await StudentValidator.Create(student))
            {
                return(student);
            }

            try
            {
                await UOW.Begin();

                student.Id = Guid.NewGuid();
                await UOW.StudentRepository.Create(student);

                User user = new User()
                {
                    Username  = student.Identify,
                    Id        = Guid.NewGuid(),
                    Password  = CryptographyExtentions.GeneratePassword(),
                    IsAdmin   = false,
                    StudentId = student.Id,
                    Email     = student.Email
                };
                await UOW.UserRepository.Create(user);

                await UOW.Commit();

                await Utils.RegisterMail(user);

                return(await UOW.StudentRepository.Get(student.Id));
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                throw new MessageException(ex);
            }
        }
コード例 #22
0
        public async Task <Student> Create(Student student)
        {
            if (!await StudentValidator.Create(student))
            {
                return(student);
            }

            using (UOW.Begin())
            {
                try
                {
                    student.Id = Guid.NewGuid();
                    await UOW.StudentRepository.Create(student);

                    var user = await UOW.UserRepository.Create(new User()
                    {
                        Id        = Guid.NewGuid(),
                        Username  = student.StudentNumber.ToString(),
                        Password  = student.StudentNumber.ToString(),
                        StudentId = student.Id,
                        IsAdmin   = false
                    });

                    await UOW.Commit();

                    return(await Get(student.Id));
                }
                catch (Exception e)
                {
                    await UOW.Rollback();

                    student.AddError(nameof(StudentService), nameof(Create), CommonEnum.ErrorCode.SystemError);
                    return(student);
                }
            }
        }
コード例 #23
0
ファイル: RoleService.cs プロジェクト: hienmx95/crm-be
        public async Task <Role> Clone(long Id)
        {
            try
            {
                Role Role = await UOW.RoleRepository.Get(Id);

                var listRolesInDb = await UOW.RoleRepository.List(new RoleFilter
                {
                    Skip = 0,
                    Take = int.MaxValue,
                    Code = new StringFilter {
                        StartWith = Role.Code + "_Clone"
                    },
                    Name = new StringFilter {
                        StartWith = Role.Name + "_Clone"
                    },
                    Selects = RoleSelect.ALL
                });

                var listPermissionsInDb = await UOW.PermissionRepository.List(new PermissionFilter
                {
                    Skip   = 0,
                    Take   = int.MaxValue,
                    RoleId = new IdFilter {
                        Equal = Role.Id
                    },
                    Selects = PermissionSelect.ALL
                });

                for (int index = 1; index < 1000; index++)
                {
                    if (listRolesInDb.Any(x => x.Code == Role.Code + "_Clone" + index.ToString() && x.Name == Role.Name + "_Clone" + index.ToString()))
                    {
                        continue;
                    }
                    Role.Code = Role.Code + "_Clone" + index.ToString();
                    Role.Name = Role.Name + "_Clone" + index.ToString();
                    break;
                }
                Role.Id = 0;
                await UOW.Begin();

                await UOW.RoleRepository.Create(Role);

                foreach (Permission Permission in listPermissionsInDb)
                {
                    Permission.RoleId = Role.Id;
                }
                await UOW.PermissionRepository.BulkMerge(listPermissionsInDb);

                await UOW.Commit();

                await Logging.CreateAuditLog(Role, new { }, nameof(RoleService));

                return(await UOW.RoleRepository.Get(Role.Id));
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(RoleService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(RoleService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #24
0
ファイル: TicketService.cs プロジェクト: hienmx95/crm-be
        public async Task <Ticket> Update(Ticket Ticket)
        {
            if (!await TicketValidator.Update(Ticket))
            {
                return(Ticket);
            }
            try
            {
                var oldData = await UOW.TicketRepository.Get(Ticket.Id);

                await UOW.Begin();

                DateTime Now = StaticParams.DateTimeNow;
                // Gán thời gian xử lý và thời gian phản hồi cho ticket từ SLAPolicy
                SLAPolicy SLAPolicy = await UOW.SLAPolicyRepository.GetByTicket(Ticket);

                if (SLAPolicy != null)
                {
                    //Ticket.SLAPolicyId = SLAPolicy.Id;
                    Ticket.FirstResponeTime = oldData.CreatedAt.AddMinutes(Utils.ConvertSLATimeToMenute(SLAPolicy.FirstResponseTime.Value, SLAPolicy.FirstResponseUnitId.Value));
                    Ticket.ResolveTime      = oldData.CreatedAt.AddMinutes(Utils.ConvertSLATimeToMenute(SLAPolicy.ResolveTime.Value, SLAPolicy.ResolveUnitId.Value));
                }
                // Ticket chuyển từ trạng thái hoạt động sang dừng
                if (!Ticket.IsWork.Value && oldData.IsWork.Value)
                {
                    Ticket.LastHoldingAt = Now;
                }
                // Ticket chuyển từ trạng thái dừng sang hoạt động
                else if (Ticket.IsWork.Value && !oldData.IsWork.Value)
                {
                    Ticket.FirstResponeTime = Now.AddMinutes(oldData.FirstRespTimeRemaining.Value);
                    Ticket.ResolveTime      = Now.AddMinutes(oldData.ResolveTimeRemaining.Value);
                    Ticket.HoldingTime      = oldData.HoldingTime + (long)(Now.Subtract(oldData.LastHoldingAt.Value).TotalMinutes);
                }
                // Lưu lại lịch sử ticket
                Ticket.TicketOfUsers = new List <TicketOfUser>();
                Ticket.TicketOfUsers.Add(
                    new TicketOfUser()
                {
                    TicketStatusId = Ticket.TicketStatusId,
                    UserId         = Ticket.UserId,
                    Notes          = Ticket.Notes,
                    TicketId       = Ticket.Id
                }
                    );
                // Đóng ticket
                if (Ticket.TicketStatusId == TicketStatusEnum.RESOLVED.Id || Ticket.TicketStatusId == TicketStatusEnum.CLOSED.Id)
                {
                    Ticket.ResolvedAt    = Now;
                    Ticket.ResolveMinute = (long)(Now.Subtract(oldData.CreatedAt).TotalMinutes);
                    Ticket.IsClose       = true;

                    var ot = (long)(Now.Subtract(Ticket.ResolveTime.Value).TotalMinutes);
                    if (ot > 0)
                    {
                        Ticket.SLAOverTime = ot;
                    }

                    if (Ticket.TicketStatusId == TicketStatusEnum.CLOSED.Id)
                    {
                        Ticket.closedAt = Now;
                    }

                    // Update trạng thái SLA
                    if (oldData.ResolveTime < Now)
                    {
                        Ticket.SLAStatusId = SLAStatusEnum.Fail.Id;
                    }
                    else
                    {
                        Ticket.SLAStatusId = SLAStatusEnum.Success.Id;
                    }
                }
                // Mở lại ticket
                if (Ticket.TicketStatusId != TicketStatusEnum.RESOLVED.Id && Ticket.TicketStatusId != TicketStatusEnum.CLOSED.Id && oldData.IsClose.Value)
                {
                    Ticket.ReraisedTimes = oldData.ReraisedTimes.Value + 1;
                    Ticket.IsClose       = false;
                }

                // Update thời gian phản hồi còn lại và thời gian xử lý còn lại
                var frtr = (long)(oldData.FirstResponeTime.Value.Subtract(Now).TotalMinutes);
                Ticket.FirstRespTimeRemaining = frtr < 0 ? 0 : frtr;
                var rtr = (long)(oldData.ResolveTime.Value.Subtract(Now).TotalMinutes);
                Ticket.ResolveTimeRemaining = rtr < 0 ? 0 : rtr;

                await UOW.TicketRepository.Update(Ticket);

                await UOW.Commit();

                Ticket = await UOW.TicketRepository.Get(Ticket.Id);

                // Push noti ticket đã sử dụng
                NotifyUsed(Ticket);

                // Thông báo cho người phụ trách ticket
                List <UserNotification> UserNotifications = new List <UserNotification>();
                var AssignUser = await UOW.AppUserRepository.Get(Ticket.UserId);

                var CurrentUser = await UOW.AppUserRepository.Get(CurrentContext.UserId);

                List <long> RecipientIds = new List <long>();
                RecipientIds.Add(Ticket.UserId);
                RecipientIds.Add(Ticket.CreatorId);
                foreach (var id in RecipientIds)
                {
                    UserNotification NotificationUtils = new UserNotification
                    {
                        TitleWeb    = $"Thông báo từ CRM",
                        ContentWeb  = $"Ticket [{Ticket.TicketNumber} - {Ticket.Name} - {Ticket.TicketIssueLevel.Name}] đã được gán cho {AssignUser.DisplayName} bởi {CurrentUser.DisplayName}",
                        LinkWebsite = $"{TicketRoute.Detail}/*".Replace("*", Ticket.Id.ToString()),
                        Time        = Now,
                        Unread      = true,
                        SenderId    = CurrentContext.UserId,
                        RecipientId = id
                    };
                    UserNotifications.Add(NotificationUtils);
                }

                await NotificationService.BulkSend(UserNotifications);

                await Logging.CreateAuditLog(Ticket, oldData, nameof(TicketService));

                return(Ticket);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(TicketService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(TicketService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #25
0
        public async Task <Notification> Send(Notification Notification)
        {
            if (!await NotificationValidator.Update(Notification))
            {
                return(Notification);
            }

            try
            {
                var oldData = await UOW.NotificationRepository.Get(Notification.Id);

                Notification.NotificationStatusId = Enums.NotificationStatusEnum.SENT.Id;
                await UOW.Begin();

                await UOW.NotificationRepository.Update(Notification);

                await UOW.Commit();

                List <AppUser> AppUsers = new List <AppUser>();
                if (Notification.OrganizationId.HasValue)
                {
                    AppUserFilter AppUserFilter = new AppUserFilter
                    {
                        Skip           = 0,
                        Take           = int.MaxValue,
                        OrganizationId = new IdFilter {
                            Equal = Notification.OrganizationId.Value
                        },
                        Selects  = AppUserSelect.Id,
                        StatusId = new IdFilter {
                            Equal = Enums.StatusEnum.ACTIVE.Id
                        }
                    };

                    AppUsers = await UOW.AppUserRepository.List(AppUserFilter);
                }
                else
                {
                    AppUserFilter AppUserFilter = new AppUserFilter
                    {
                        Skip     = 0,
                        Take     = int.MaxValue,
                        Selects  = AppUserSelect.Id,
                        StatusId = new IdFilter {
                            Equal = Enums.StatusEnum.ACTIVE.Id
                        }
                    };

                    AppUsers = await UOW.AppUserRepository.List(AppUserFilter);
                }

                if (AppUsers != null && AppUsers.Any())
                {
                    var AppUserIds = AppUsers.Select(x => x.Id).ToList();

                    List <UserNotification> UserNotifications = AppUserIds.Select(x => new UserNotification
                    {
                        TitleWeb    = $"Thông báo từ CRM",
                        ContentWeb  = Notification.Content,
                        LinkWebsite = $"{NotificationRoute.Detail}".Replace("*", Notification.Id.ToString()),
                        LinkMobile  = $"{NotificationRoute.Mobile}".Replace("*", Notification.Id.ToString()),
                        Time        = StaticParams.DateTimeNow,
                        Unread      = false,
                        SenderId    = CurrentContext.UserId,
                        RecipientId = x
                    }).ToList();

                    //await BulkSend(NotificationUtilss);
                    List <EventMessage <UserNotification> > EventUserNotifications = UserNotifications.Select(x => new EventMessage <UserNotification>(x, x.RowId)).ToList();
                    RabbitManager.PublishList(EventUserNotifications, RoutingKeyEnum.UserNotificationSend);
                }

                var newData = await UOW.NotificationRepository.Get(Notification.Id);

                await Logging.CreateAuditLog(newData, oldData, nameof(NotificationService));

                return(newData);
            }
            catch (Exception ex)
            {
                await UOW.Rollback();

                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(NotificationService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(NotificationService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }