public async Task <OperationDataResult <CaseManagementBaseSettings> > GetSettings()
        {
            try
            {
                var option = _options.Value;
                if (option.SdkConnectionString == "...")
                {
                    string connectionString = _dbContext.Database.GetDbConnection().ConnectionString;

                    string dbNameSection = Regex.Match(connectionString, @"(Database=(...)_eform-angular-\w*-plugin;)").Groups[0].Value;
                    string dbPrefix      = Regex.Match(connectionString, @"Database=(\d*)_").Groups[1].Value;
                    string sdk           = $"Database={dbPrefix}_SDK;";
                    connectionString = connectionString.Replace(dbNameSection, sdk);
                    await _options.UpdateDb(settings => { settings.SdkConnectionString = connectionString; }, _dbContext, UserId);
                }

//                CaseManagementPnSettingsModel result = new CaseManagementPnSettingsModel();
//                CaseManagementSetting customerSettings = _dbContext.CaseManagementSettings.FirstOrDefault();
//                if (customerSettings?.SelectedTemplateId != null && customerSettings?.RelatedEntityGroupId != null)
//                {
//                    result.SelectedTemplateId = (int) customerSettings.SelectedTemplateId;
//                    result.SelectedTemplateName = customerSettings.SelectedTemplateName;
//                    result.RelatedEntityGroupId = customerSettings.RelatedEntityGroupId;
//                    Core core = _coreHelper.GetCore();
//                    EntityGroup entityGroup = core.EntityGroupRead(customerSettings.RelatedEntityGroupId.ToString());
//                    if (entityGroup == null)
//                    {
//                        return new OperationDataResult<CaseManagementPnSettingsModel>(false, "Entity group not found");
//                    }
//
//                    result.RelatedEntityGroupName = entityGroup.Name;
//                }
//                else
//                {
//                    result.RelatedEntityGroupId = null;
//                    result.SelectedTemplateId = null;
//                }

                return(new OperationDataResult <CaseManagementBaseSettings>(true, option));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <CaseManagementBaseSettings>(false,
                                                                            _caseManagementLocalizationService.GetString("ErrorWhileObtainingCaseManagementSettings")));
            }
        }
        public async Task <OperationDataResult <List <CalendarEventModel> > > Index(CalendarEventsRequestModel requestModel)
        {
            try
            {
                var calendarEventModels = new List <CalendarEventModel>();
                var core  = _coreHelper.GetCore();
                var cases = await core.Result.CaseReadAll(requestModel.TemplateId, requestModel.StartDate, requestModel.EndDate, null);

                var casesSiteIds = cases.Where(x => x.SiteId != null)
                                   .Select(x => x.SiteId)
                                   .GroupBy(x => x)
                                   .Select(x => (int)x.Key)
                                   .ToList();

                var calendarUsers = _dbContext.CalendarUsers
                                    .Where(x => casesSiteIds.Contains(x.SiteId) && x.IsVisibleInCalendar)
                                    .ToList();

                foreach (var caseItem in cases)
                {
                    if (caseItem.SiteId != null)
                    {
                        var siteId       = caseItem.SiteId;
                        var calendarUser = calendarUsers.FirstOrDefault(x => x.SiteId == siteId);
                        if (calendarUser != null)
                        {
                            var dateParseResult = DateTime.TryParseExact(caseItem.FieldValue1,
                                                                         "yyyy-MM-dd",
                                                                         null,
                                                                         DateTimeStyles.None,
                                                                         out DateTime date);
                            var item = new CalendarEventModel
                            {
                                Color = calendarUser.Color,
                                Title = caseItem.FieldValue2
                            };
                            if (dateParseResult)
                            {
                                item.Start = date;
                                item.End   = date;
                            }
                            item.Meta = new CalendarEventMeta
                            {
                                CaseId           = caseItem.Id.ToString(),
                                CalendarUserName = calendarUser.NameInCalendar
                            };
                            // Add item
                            calendarEventModels.Add(item);
                        }
                    }
                }

                return(new OperationDataResult <List <CalendarEventModel> >(true, calendarEventModels));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <List <CalendarEventModel> >(false,
                                                                            _caseManagementLocalizationService.GetString("ErrorObtainingCalendarInfo")));
            }
        }
Пример #3
0
        public async Task <OperationDataResult <CalendarUsersModel> > Index(CalendarUsersRequestModel requestModel)
        {
            try
            {
                CalendarUsersModel        calendarUsersModel = new CalendarUsersModel();
                IQueryable <CalendarUser> calendarUsersQuery = _dbContext.CalendarUsers.AsQueryable();
                if (!string.IsNullOrEmpty(requestModel.Sort))
                {
                    if (requestModel.IsSortDsc)
                    {
                        calendarUsersQuery = calendarUsersQuery
                                             .OrderByDescending(requestModel.Sort);
                    }
                    else
                    {
                        calendarUsersQuery = calendarUsersQuery
                                             .OrderBy(requestModel.Sort);
                    }
                }
                else
                {
                    calendarUsersQuery = _dbContext.CalendarUsers
                                         .OrderBy(x => x.Id);
                }

                calendarUsersQuery = calendarUsersQuery
                                     .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                                     .Skip(requestModel.Offset)
                                     .Take(requestModel.PageSize);

                List <CalendarUser> calendarUsers = await calendarUsersQuery.ToListAsync();

                calendarUsersModel.Total = await _dbContext.CalendarUsers.CountAsync();

                Core core = await _coreHelper.GetCore();

                calendarUsers.ForEach(calendarUser =>
                {
                    CalendarUserModel item = new CalendarUserModel
                    {
                        Id     = calendarUser.Id,
                        SiteId = calendarUser.SiteId,
                        IsVisibleInCalendar = calendarUser.IsVisibleInCalendar,
                        NameInCalendar      = calendarUser.NameInCalendar,
                        Color = calendarUser.Color,
                    };
                    if (item.SiteId > 0)
                    {
                        SiteDto site = core.SiteRead(item.SiteId).Result;
                        if (site != null)
                        {
                            item.FirstName = site.FirstName;
                            item.LastName  = site.LastName;
                        }
                    }

                    calendarUsersModel.CalendarUsers.Add(item);
                });
                return(new OperationDataResult <CalendarUsersModel>(true, calendarUsersModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <CalendarUsersModel>(false,
                                                                    _caseManagementLocalizationService.GetString("ErrorWhileObtainingCalendarUserInfo")));
            }
        }