コード例 #1
0
        public async Task <SLAEscalation> Create(SLAEscalation SLAEscalation)
        {
            if (!await SLAEscalationValidator.Create(SLAEscalation))
            {
                return(SLAEscalation);
            }

            try
            {
                await UOW.Begin();

                await UOW.SLAEscalationRepository.Create(SLAEscalation);

                await UOW.Commit();

                SLAEscalation = await UOW.SLAEscalationRepository.Get(SLAEscalation.Id);

                await Logging.CreateAuditLog(SLAEscalation, new { }, nameof(SLAEscalationService));

                return(SLAEscalation);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(SLAEscalationService));

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

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

            try
            {
                await UOW.Begin();

                await UOW.KnowledgeGroupRepository.Create(KnowledgeGroup);

                await UOW.Commit();

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

                await Logging.CreateAuditLog(KnowledgeGroup, new { }, nameof(KnowledgeGroupService));

                return(KnowledgeGroup);
            }
            catch (Exception ex)
            {
                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);
                }
            }
        }
コード例 #3
0
        public async Task <KpiGeneralContent> Create(KpiGeneralContent KpiGeneralContent)
        {
            if (!await KpiGeneralContentValidator.Create(KpiGeneralContent))
            {
                return(KpiGeneralContent);
            }

            try
            {
                await UOW.Begin();

                await UOW.KpiGeneralContentRepository.Create(KpiGeneralContent);

                await UOW.Commit();

                KpiGeneralContent = await UOW.KpiGeneralContentRepository.Get(KpiGeneralContent.Id);

                await Logging.CreateAuditLog(KpiGeneralContent, new { }, nameof(KpiGeneralContentService));

                return(KpiGeneralContent);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(KpiGeneralContentService));

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

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
ファイル: CallsController.cs プロジェクト: vlarok/web
 public void Generate()
 {
     //:TODO meil on vaja kontroll teha kui custom väljad on nullid
     for (int i = 0; i < 30; i++)
     {
         for (int j = 1; j < 1000; j++)
         {
             _uow.Calls.AddCall(new Call()
             {
                 AudioDir      = @"2015\04\27\22\",
                 AudioFileName = "20150427225942_001_50336869",
                 Anumber       = "16684" + i.ToString(),
                 Bnumber       = i.ToString() + "98991",
                 Dir           = "in",
                 Duration      = "1" + i.ToString(),
                 UserId        = 1,
                 ServiceId     = 1,
                 Created       = DateTime.Now.AddMinutes(-j),
                 Custom1       = "1"
             });
             _uow.Commit();
         }
     }
 }
コード例 #7
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);
            }
        }
コード例 #8
0
        public async Task <University_Majors_SubjectGroup> Create(University_Majors_SubjectGroup university_Majors_SubjectGroup)
        {
            university_Majors_SubjectGroup.Id = Guid.NewGuid();
            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);
            }
        }
コード例 #9
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);
        }
コード例 #10
0
        public async Task <User> ChangePassword(User user, string newPassword)
        {
            // Xác thực dữ liệu thay đổi password
            if (!await UserValidator.Update(user, newPassword))
            {
                return(user);
            }

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

                    user.Password = newPassword;

                    await UOW.UserRepository.Update(user);

                    await UOW.Commit();

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

                    user.AddError(nameof(UserService), nameof(ChangePassword), Common.ErrorCode.SystemError);
                    return(user);
                }
            }
        }
コード例 #11
0
ファイル: FileService.cs プロジェクト: hienmx95/crm-be
        public async Task <Entities.File> Create(Entities.File File, string path)
        {
            RestClient  restClient  = new RestClient(InternalServices.UTILS);
            RestRequest restRequest = new RestRequest("/rpc/utils/file/upload");

            restRequest.RequestFormat = DataFormat.Json;
            restRequest.Method        = Method.POST;
            restRequest.AddCookie("Token", CurrentContext.Token);
            restRequest.AddCookie("X-Language", CurrentContext.Language);
            restRequest.AddHeader("Content-Type", "multipart/form-data");
            restRequest.AddFile("file", File.Content, File.Name);
            restRequest.AddParameter("path", path);
            try
            {
                var response = restClient.Execute <Entities.File>(restRequest);
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    File.Id        = response.Data.Id;
                    File.Url       = "/rpc/utils/file/download" + response.Data.Path;
                    File.AppUserId = File.AppUserId;
                    File.RowId     = response.Data.RowId;
                    await UOW.Begin();

                    await UOW.FileRepository.Create(File);

                    File = await UOW.FileRepository.Get(File.Id);

                    await UOW.Commit();

                    return(File);
                }
                return(null);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #12
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);
            }
        }
コード例 #13
0
        public async Task <CustomerLead> Create(CustomerLead CustomerLead)
        {
            if (!await CustomerLeadValidator.Create(CustomerLead))
            {
                return(CustomerLead);
            }

            try
            {
                await UOW.Begin();

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

                CustomerLead.CreatorId            = Creator.Id;
                CustomerLead.OrganizationId       = Creator.OrganizationId;
                CustomerLead.CustomerLeadStatusId = CustomerLeadStatusEnum.NEW.Id;
                await UOW.CustomerLeadRepository.Create(CustomerLead);

                await UOW.CustomerLeadRepository.Update(CustomerLead);

                await UOW.Commit();

                CustomerLead = await UOW.CustomerLeadRepository.Get(CustomerLead.Id);

                await Logging.CreateAuditLog(CustomerLead, new { }, nameof(CustomerLeadService));

                return(CustomerLead);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(CustomerLeadService));

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

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

            try
            {
                await UOW.Begin();

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

                Opportunity.CreatorId      = Creator.Id;
                Opportunity.OrganizationId = Creator.OrganizationId;
                Opportunity.SaleStageId    = OpportunityStatusEnum.MOI.Id;
                await UOW.OpportunityRepository.Create(Opportunity);

                await UOW.Commit();

                Opportunity = await UOW.OpportunityRepository.Get(Opportunity.Id);

                await Logging.CreateAuditLog(Opportunity, new { }, nameof(OpportunityService));

                return(Opportunity);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(OpportunityService));

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

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #15
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);
            }
        }
コード例 #16
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);
                }
            }
        }
コード例 #17
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);
                }
            }
        }
コード例 #18
0
        public async Task <TicketIssueLevel> Create(TicketIssueLevel TicketIssueLevel)
        {
            if (!await TicketIssueLevelValidator.Create(TicketIssueLevel))
            {
                return(TicketIssueLevel);
            }

            try
            {
                TicketIssueLevelFilter TicketIssueLevelFilter = new TicketIssueLevelFilter
                {
                    Take      = 1,
                    Selects   = TicketIssueLevelSelect.ALL,
                    OrderBy   = TicketIssueLevelOrder.OrderNumber,
                    OrderType = OrderType.DESC
                };

                await UOW.Begin();

                if (TicketIssueLevel.OrderNumber == 0)
                {
                    List <TicketIssueLevel> TicketIssueLevels = await UOW.TicketIssueLevelRepository.List(TicketIssueLevelFilter);

                    TicketIssueLevel.OrderNumber = TicketIssueLevels.Any() ? TicketIssueLevels.Max(c => c.OrderNumber) + 1 : 1;
                }
                // Nhắc nhở xử lý
                List <SLAAlert> SLAAlerts = new List <SLAAlert>();
                if (TicketIssueLevel.SLAAlerts != null && TicketIssueLevel.SLAAlerts.Any())
                {
                    foreach (var SLAAlert in TicketIssueLevel.SLAAlerts)
                    {
                        var newObj = SLAAlert;
                        newObj.RowId = Guid.NewGuid();
                        if (!newObj.Time.HasValue)
                        {
                            newObj.Time       = 15;
                            newObj.TimeUnitId = SLATimeUnitEnum.MINUTES.Id;
                        }
                        SLAAlerts.Add(newObj);
                    }
                }
                TicketIssueLevel.SLAAlerts = SLAAlerts;
                // Nhắc nhở phản hồi
                List <SLAAlertFRT> SLAAlertFRTs = new List <SLAAlertFRT>();
                if (TicketIssueLevel.SLAAlertFRTs != null && TicketIssueLevel.SLAAlertFRTs.Any())
                {
                    foreach (var SLAAlertFRT in TicketIssueLevel.SLAAlertFRTs)
                    {
                        var newObj = SLAAlertFRT;
                        newObj.RowId = Guid.NewGuid();
                        if (!newObj.Time.HasValue)
                        {
                            newObj.Time       = 15;
                            newObj.TimeUnitId = SLATimeUnitEnum.MINUTES.Id;
                        }
                        SLAAlertFRTs.Add(newObj);
                    }
                }
                TicketIssueLevel.SLAAlertFRTs = SLAAlertFRTs;
                // Cảnh báo xử lý
                List <SLAEscalation> SLAEscalations = new List <SLAEscalation>();
                if (TicketIssueLevel.SLAEscalations != null && TicketIssueLevel.SLAEscalations.Any())
                {
                    foreach (var SLAEscalation in TicketIssueLevel.SLAEscalations)
                    {
                        var newObj = SLAEscalation;
                        newObj.RowId = Guid.NewGuid();
                        if (!newObj.Time.HasValue)
                        {
                            newObj.Time       = 15;
                            newObj.TimeUnitId = SLATimeUnitEnum.MINUTES.Id;
                        }
                        SLAEscalations.Add(newObj);
                    }
                }
                TicketIssueLevel.SLAEscalations = SLAEscalations;
                // Cảnh báo phản hồi
                List <SLAEscalationFRT> SLAEscalationFRTs = new List <SLAEscalationFRT>();
                if (TicketIssueLevel.SLAEscalationFRTs != null && TicketIssueLevel.SLAEscalationFRTs.Any())
                {
                    foreach (var SLAEscalationFRT in TicketIssueLevel.SLAEscalationFRTs)
                    {
                        var newObj = SLAEscalationFRT;
                        newObj.RowId = Guid.NewGuid();
                        if (!newObj.Time.HasValue)
                        {
                            newObj.Time       = 15;
                            newObj.TimeUnitId = SLATimeUnitEnum.MINUTES.Id;
                        }
                        SLAEscalationFRTs.Add(newObj);
                    }
                }
                TicketIssueLevel.SLAEscalationFRTs = SLAEscalationFRTs;

                await UOW.TicketIssueLevelRepository.Create(TicketIssueLevel);

                await UOW.Commit();

                TicketIssueLevel = await UOW.TicketIssueLevelRepository.Get(TicketIssueLevel.Id);

                await Logging.CreateAuditLog(TicketIssueLevel, new { }, nameof(TicketIssueLevelService));

                return(TicketIssueLevel);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(TicketIssueLevelService));

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

                    throw new MessageException(ex.InnerException);
                }
            }
        }
コード例 #19
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);
                }
            }
        }
コード例 #20
0
ファイル: TicketService.cs プロジェクト: hienmx95/crm-be
        public async Task <Ticket> Create(Ticket Ticket)
        {
            if (!await TicketValidator.Create(Ticket))
            {
                return(Ticket);
            }

            try
            {
                await UOW.Begin();

                var newId = await TicketGeneratedIdService.GetNewTicketId();

                Ticket.TicketNumber   = newId.Id.ToString().PadLeft(6, '0');
                Ticket.UserId         = CurrentContext.UserId;
                Ticket.CreatorId      = CurrentContext.UserId;
                Ticket.Subject        = "";
                Ticket.SLA            = Ticket.TicketIssueLevel.SLA;
                Ticket.IsAlerted      = false;
                Ticket.IsAlertedFRT   = false;
                Ticket.IsEscalated    = false;
                Ticket.IsEscalatedFRT = false;
                Ticket.IsClose        = false;
                Ticket.IsOpen         = true;
                Ticket.IsWait         = false;
                Ticket.IsWork         = true;
                Ticket.ReraisedTimes  = 0;
                Ticket.HoldingTime    = 0;
                Ticket.TicketStatusId = TicketStatusEnum.NEW.Id;
                Ticket.TicketOfUsers  = new List <TicketOfUser>();
                Ticket.TicketOfUsers.Add(
                    new TicketOfUser()
                {
                    TicketStatusId = TicketStatusEnum.NEW.Id,
                    UserId         = Ticket.UserId
                }
                    );
                SLAPolicy SLAPolicy = await UOW.SLAPolicyRepository.GetByTicket(Ticket);

                DateTime Now = StaticParams.DateTimeNow;
                if (SLAPolicy != null)
                {
                    // Ticket.SLAPolicyId = SLAPolicy.Id;
                    Ticket.FirstResponeTime = Now.AddMinutes(Utils.ConvertSLATimeToMenute(SLAPolicy.FirstResponseTime.Value, SLAPolicy.FirstResponseUnitId.Value));
                    Ticket.ResolveTime      = Now.AddMinutes(Utils.ConvertSLATimeToMenute(SLAPolicy.ResolveTime.Value, SLAPolicy.ResolveUnitId.Value));
                }
                await UOW.TicketRepository.Create(Ticket);

                await TicketGeneratedIdService.UpdateUsed(int.Parse(Ticket.TicketNumber));

                await UOW.Commit();

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

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

                var RecipientIds = await UOW.PermissionRepository.ListAppUser(TicketRoute.Update);

                List <UserNotification> UserNotifications = new List <UserNotification>();
                //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 thêm mới lên hệ thống bởi {CurrentUser.DisplayName}",
                    LinkWebsite = $"{TicketRoute.Detail}/*".Replace("*", Ticket.Id.ToString()),
                    Time        = Now,
                    Unread      = true,
                    SenderId    = CurrentContext.UserId,
                    RecipientId = CurrentContext.UserId,
                    RowId       = Guid.NewGuid(),
                };
                UserNotifications.Add(NotificationUtils);
                //}

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


                await Logging.CreateAuditLog(Ticket, new { }, nameof(TicketService));

                return(Ticket);
            }
            catch (Exception ex)
            {
                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);
                }
            }
        }