public static List<SubEntityRecord> GetDropdownValues(LocationAdminDetailView parent, int orgUnitId)
        {
            IEnumerable<OrgUnitInsuranceDto> existingInsurances = new List<OrgUnitInsuranceDto>();
            if (orgUnitId != 0)
                existingInsurances = GetOrgUnitInsurances(parent, orgUnitId);

            var request = new ListInsurancesRequest() { IsEnabled = true };
            var insurances = parent.ProcessRequest<ListInsurancesResponse>(request).Insurances;
            var records = new List<SubEntityRecord>();

            foreach (var insurance in insurances.Where(i => !existingInsurances.Any(e => e.InsuranceId == i.Id)))
            {
                var record = new SubEntityRecord();
                record.DisplayName = insurance.Name;
                record.Id = insurance.Id;
                record.Fields.Add(new Field(_idField, "Id", FieldTypes.Hidden, null));
                record.Fields.Add(new Field(_orgUnitIdField, _orgUnitIdField, FieldTypes.Hidden, orgUnitId));
                record.Fields.Add(new Field(_insuranceIdField, _insuranceIdField, FieldTypes.Hidden, insurance.Id));
                record.Fields.Add(new Field(_nameField, "Name", FieldTypes.Label, insurance.Name));

                records.Add(record);
            }

            return records;
        }
        public static List<SubEntityRecord> GetDropdownValues(LocationAdminDetailView parent, int orgUnitId)
        {
            IEnumerable<OrgUnitOrgUnitTypeDto> existingTypes = new List<OrgUnitOrgUnitTypeDto>();
            if (orgUnitId != 0)
                existingTypes = GetOrgUnitOrgUnitTypes(parent, orgUnitId);

            var request = new ListOrgUnitTypesRequest() { IsEnabled = true };
            var types = parent.ProcessRequest<ListOrgUnitTypesResponse>(request).OrgUnitTypes;
            var records = new List<SubEntityRecord>();

            foreach (var type in types.Where(t => !existingTypes.Any(e => e.OrgUnitTypeId == t.Id)))
            {
                var record = new SubEntityRecord();
                record.DisplayName = type.Name;
                record.Id = type.Id;
                record.Fields.Add(new Field(_idField, "Id", FieldTypes.Hidden, null));
                record.Fields.Add(new Field(_orgUnitIdField, _orgUnitIdField, FieldTypes.Hidden, orgUnitId));
                record.Fields.Add(new Field(_orgUnitTypeIdField, _orgUnitTypeIdField, FieldTypes.Hidden, type.Id));
                record.Fields.Add(new Field(_nameField, "Name", FieldTypes.Label, type.Name));
                record.Fields.Add(new Field(_isPrimaryOrgUnitTypeField, "Is Primary", FieldTypes.Checkbox, false, true));

                records.Add(record);
            }

            return records;
        }
        public static SubEntity BuildLocationSitesSubEntity(LocationAdminDetailView parent, OrgUnitDto orgUnitDto, SubEntity locationTypeSubEntity)
        {
            _subEntity = parent._viewModel.SubEntities.FirstOrDefault(s => s.EntityName == LocationAdminDetailView._locationTypeSubEntity);

            if (_subEntity == null)
                _subEntity = new SubEntity() { EntityName = LocationAdminDetailView._locationSiteSubEntity, DisplayName = "Site Association", CanAddExisting = false, CanCreateNew = false, CanDelete = false };
            else
                _subEntity.Records = new List<SubEntityRecord>();

            AddExistingRecords(orgUnitDto, locationTypeSubEntity);

            return _subEntity;
        }
        public static SubEntity BuildLocationInsurancesSubEntity(LocationAdminDetailView parent, int orgUnitId)
        {
            _subEntity = parent._viewModel.SubEntities.FirstOrDefault(s => s.EntityName == LocationAdminDetailView._locationInsuranceSubEntity);

            if (_subEntity == null)
                _subEntity = new SubEntity() { EntityName = LocationAdminDetailView._locationInsuranceSubEntity, DisplayName = "Insurances", CanAddExisting = true, CanCreateNew = true, CanDelete = true };
            else
                _subEntity.Records = new List<SubEntityRecord>();

            AddExistingRecords(parent, orgUnitId);
            AddNewRecordTemplate(parent, orgUnitId);

            return _subEntity;
        }
        public static void Save(LocationAdminDetailView parent, SubEntity hours, int orgUnitId)
        {
            var partiallySaved = false;

            try
            {
                hours.ErrorMessage = string.Empty;

                //New
                foreach (var record in hours.Records.Where(r => r.Action == RecordActions.New))
                {
                    var timeSpan = CommonUtils.CreateScheduleTimeSpan(parent.GetFieldValue(record.Fields, _dayField), parent.GetFieldValue(record.Fields, _openTime), parent.GetFieldValue(record.Fields, _closeTime));

                    var request = new AddOrgUnitScheduleRequest()
                    {
                        LocationId = int.Parse(parent.GetFieldValue(record.Fields, _orgUnitIdField)),
                        OpenTime = timeSpan.OpenTime,
                        OpenHours = timeSpan.OpenHours
                    };

                    parent.ProcessRequest<AddOrgUnitScheduleResponse>(request);
                    partiallySaved = true;
                }

                //Deletes
                foreach (var record in hours.Records.Where(r => r.Action == RecordActions.Deleted))
                {
                    var request = new DeleteOrgUnitScheduleRequest(int.Parse(parent.GetFieldValue(record.Fields, _idField)));
                    parent.ProcessRequest<DeleteOrgUnitScheduleResponse>(request);
                    partiallySaved = true;
                }
            }
            catch (Exception ex)
            {
                hours.ErrorMessage = ex.Message;

                if(!partiallySaved)
                    throw;
            }

            hours = BuildLocationHoursSubEntity(parent, orgUnitId);
        }
        public static void PopulateRequestFieldValues(LocationAdminDetailView parent, SubEntity sites, int orgUnitId, OrgUnitRequestBase request)
        {
            var record = sites.Records.SingleOrDefault(r => r.Action == RecordActions.Edited);

            if (record == null)
                return;

            request.CustomUrl = parent.GetFieldValue(record.Fields, _siteUrlField);
            request.CustomLiveUrl = parent.GetFieldValue(record.Fields, _siteUrlLiveField);
            request.CustomStageUrl = parent.GetFieldValue(record.Fields, _siteUrlStageField);
            request.CustomQaUrl = parent.GetFieldValue(record.Fields, _siteUrlQaField);
            request.CustomDevUrl = parent.GetFieldValue(record.Fields, _siteUrlDevField);

            // Determine if site association is enabled
            var associationEnabled = false;
            bool.TryParse(CommonUtils.GetFieldValue(record.Fields, _associationEnabledField), out associationEnabled);

            // Add/remove "Site" location type automatically if site association is enabled/disabled
            var locationTypeSubEntity = parent._viewModel.SubEntities.Single(s => s.EntityName == LocationAdminDetailView._locationTypeSubEntity);
            var hasSiteLocationType = HasSiteLocationType(locationTypeSubEntity);

            if (associationEnabled && !hasSiteLocationType)
            {
                var orgUnitType = new OrgUnitOrgUnitTypeDto
                {
                    OrgUnitTypeId = 1,
                    IsEnabled = true,
                    IsPrimaryOrgUnitType = false
                };

                var locationTypeRecord = LocationTypesHelper.CreateRecord(orgUnitType, orgUnitId);
                locationTypeRecord.Action = RecordActions.Added;
                locationTypeSubEntity.Records.Add(locationTypeRecord);
            }
            else if (!associationEnabled && hasSiteLocationType)
            {
                var siteLocationTypeRecord = locationTypeSubEntity.Records.SingleOrDefault(s => s.Fields.Any(f => f.FieldName == "Name" && (f.FieldValue as string == "Site")));

                if (siteLocationTypeRecord != null && siteLocationTypeRecord.Action != RecordActions.Added)
                    siteLocationTypeRecord.Action = RecordActions.Deleted;
            }
        }
        public static void Save(LocationAdminDetailView parent, SubEntity insurances, int orgUnitId)
        {
            var partiallySaved = false;

            try
            {
                insurances.ErrorMessage = string.Empty;

                //Existing Records Added
                foreach (var record in insurances.Records.Where(r => r.Action == RecordActions.Added))
                {
                    var request = new AddOrgUnitInsuranceRequest()
                    {
                        OrgUnitId = orgUnitId,
                        InsuranceId = int.Parse(parent.GetFieldValue(record.Fields, _insuranceIdField))
                    };

                    parent.ProcessRequest<AddOrgUnitInsuranceResponse>(request);
                    partiallySaved = true;
                }

                //New Records Created
                foreach (var record in insurances.Records.Where(r => r.Action == RecordActions.New))
                {
                    //Add New OrgUnit insurance
                    var addInsuranceRequest = new AddInsuranceRequest()
                    {
                        Name = parent.GetFieldValue(record.Fields, _nameField),
                        IsEnabled = true
                    };
                    var addedInsuranceId = parent.ProcessRequest<AddInsuranceResponse>(addInsuranceRequest).Id;

                    //Add newly created insurance to OrgUnit
                    var request = new AddOrgUnitInsuranceRequest()
                    {
                        OrgUnitId = orgUnitId,
                        InsuranceId = addedInsuranceId
                    };

                    parent.ProcessRequest<AddOrgUnitInsuranceResponse>(request);
                    partiallySaved = true;
                }

                //Deletes
                foreach (var record in insurances.Records.Where(r => r.Action == RecordActions.Deleted))
                {
                    var request = new RemoveOrgUnitInsuranceRequest()
                    {
                        Id = int.Parse(parent.GetFieldValue(record.Fields, _idField))
                    };
                    parent.ProcessRequest<RemoveOrgUnitInsuranceResponse>(request);
                    partiallySaved = true;
                }
            }
            catch (Exception ex)
            {
                insurances.ErrorMessage = ex.Message;

                if(!partiallySaved)
                    throw;
            }

            insurances = BuildLocationInsurancesSubEntity(parent, orgUnitId);
        }
 private static IEnumerable<OrgUnitInsuranceDto> GetOrgUnitInsurances(LocationAdminDetailView parent, int orgUnitId)
 {
     var request = new ListOrgUnitInsurancesRequest(orgUnitId);
     return parent.ProcessRequest<ListOrgUnitInsurancesResponse>(request).OrgUnitInsurances;
 }
 private static void AddNewRecordTemplate(LocationAdminDetailView parent, int orgUnitId)
 {
     _subEntity.NewRecordTemplate = new SubEntityRecord()
     {
         Fields =
         {
             new Field(_idField, "Id", FieldTypes.Hidden, null),
             new Field(_orgUnitIdField, _orgUnitIdField, FieldTypes.Hidden, orgUnitId),
             new Field(_nameField, "Name", FieldTypes.Text, string.Empty, true),
         }
     };
 }
        private static void AddExistingRecords(LocationAdminDetailView parent, int orgUnitId)
        {
            var insurances = GetOrgUnitInsurances(parent, orgUnitId);

            foreach (var insurance in insurances)
            {
                var record = new SubEntityRecord();
                var fields = new List<Field>();

                fields.Add(new Field(_idField, _idField, FieldTypes.Hidden, insurance.Id));
                fields.Add(new Field(_orgUnitIdField, _orgUnitIdField, FieldTypes.Hidden, orgUnitId));
                fields.Add(new Field(_insuranceIdField, _insuranceIdField, FieldTypes.Hidden, insurance.InsuranceId));
                fields.Add(new Field(_nameField, "Name", FieldTypes.Label, insurance.InsuranceName));

                record.Fields = fields;

                _subEntity.Records.Add(record);
            }
        }
示例#11
0
 private static IEnumerable<OrgUnitScheduleListItem> GetOrgUnitHours(LocationAdminDetailView parent, int orgUnitId)
 {
     var request = new ListOrgUnitScheduleRequest(orgUnitId);
     return parent.ProcessRequest<ListOrgUnitScheduleResponse>(request).ScheduleTimeSpans;
 }
示例#12
0
 private static void AddNewRecordTemplate(LocationAdminDetailView parent, int orgUnitId)
 {
     _subEntity.NewRecordTemplate = new SubEntityRecord()
     {
         Fields =
         {
             new Field(_idField, "Id", FieldTypes.Hidden, null),
             new Field(_orgUnitIdField, _orgUnitIdField, FieldTypes.Hidden, orgUnitId),
             new Field(_nameField, "Name", FieldTypes.Text, string.Empty, true),
             new Field(_isEnabledField, "Enabled", FieldTypes.Checkbox, true),
             new Field(_isExternalField, "Outside of Organization", FieldTypes.Checkbox, false),
             new Field(_siteIndicatorField, "Designates a Site Root", FieldTypes.Checkbox, false),
             new Field(_imageUrlField, "Image URL", FieldTypes.Text, string.Empty),
             new Field(_isPrimaryOrgUnitTypeField, "Is Primary", FieldTypes.Checkbox, false, true),
         }
     };
 }
示例#13
0
        private static void AddExistingRecords(LocationAdminDetailView parent, int orgUnitId)
        {
            var locationTypes = GetOrgUnitOrgUnitTypes(parent, orgUnitId);

            foreach (var type in locationTypes)
            {
                _subEntity.Records.Add(CreateRecord(type, orgUnitId));
            }
        }
 private static IEnumerable<OrgUnitServicesDto> GetOrgUnitServices(LocationAdminDetailView parent, int orgUnitId)
 {
     var request = new ListOrgUnitServicesRequest(orgUnitId) { IsAdminView = true };
     return parent.ProcessRequest<ListOrgUnitServicesResponse>(request).OrgUnitServices;
 }
示例#15
0
        private static void AddExistingRecords(LocationAdminDetailView parent, int orgUnitId)
        {
            var hours = GetOrgUnitHours(parent, orgUnitId);

            foreach (var hour in hours)
            {
                var record = new SubEntityRecord();
                var fields = new List<Field>();

                fields.Add(new Field(_idField, _idField, FieldTypes.Hidden, hour.Id));
                fields.Add(new Field(_orgUnitIdField, _orgUnitIdField, FieldTypes.Hidden, orgUnitId));
                fields.Add(new Field(_descriptionField, hour.Day, FieldTypes.Label, hour.Open + " - " + hour.Close));

                record.Fields = fields;

                _subEntity.Records.Add(record);
            }
        }
示例#16
0
        public static void Save(LocationAdminDetailView parent, SubEntity orgUnitTypes, int orgUnitId)
        {
            var partiallySaved = false;

            try
            {
                orgUnitTypes.ErrorMessage = string.Empty;

                if (orgUnitTypes.Records.Count(s => s.Fields.Any(f => f.FieldName == _isPrimaryOrgUnitTypeField) && bool.Parse(parent.GetFieldValue(s.Fields, _isPrimaryOrgUnitTypeField))) > 1)
                    throw new BusinessException("Only one Location Type can be set as the primary location");

                //Edits
                foreach (var record in orgUnitTypes.Records.Where(r => r.Action == RecordActions.Edited))
                {
                    var request = new UpdateOrgUnitOrgUnitTypeRequest
                    {
                        Id = int.Parse(parent.GetFieldValue(record.Fields, _idField)),
                        OrgUnitId = orgUnitId,
                        OrgUnitTypeId = int.Parse(parent.GetFieldValue(record.Fields, _orgUnitTypeIdField)),
                        IsPrimaryOrgUnitType = bool.Parse(parent.GetFieldValue(record.Fields, _isPrimaryOrgUnitTypeField))
                    };

                    parent.ProcessRequest<UpdateOrgUnitOrgUnitTypeResponse>(request);
                    partiallySaved = true;
                }

                //Existing Records Added
                foreach (var record in orgUnitTypes.Records.Where(r => r.Action == RecordActions.Added))
                {
                    var request = new AddOrgUnitOrgUnitTypeRequest()
                    {
                        OrgUnitId = orgUnitId,
                        OrgUnitTypeId = int.Parse(parent.GetFieldValue(record.Fields, _orgUnitTypeIdField)),
                        IsPrimaryOrgUnitType = bool.Parse(parent.GetFieldValue(record.Fields, _isPrimaryOrgUnitTypeField)),
                    };

                    parent.ProcessRequest<AddOrgUnitOrgUnitTypeResponse>(request);
                    partiallySaved = true;
                }

                //New Records Created
                foreach (var record in orgUnitTypes.Records.Where(r => r.Action == RecordActions.New))
                {
                    //Add New OrgUnit Type
                    var addTypeRequest = new AddOrgUnitTypeRequest()
                    {
                        Name = parent.GetFieldValue(record.Fields, _nameField),
                        IsEnabled = bool.Parse(parent.GetFieldValue(record.Fields, _isEnabledField)),
                        IsOutsideOfOrganization = bool.Parse(parent.GetFieldValue(record.Fields, _isExternalField)),
                        SiteIndicator = bool.Parse(parent.GetFieldValue(record.Fields, _siteIndicatorField)),
                        ImageUrl = parent.GetFieldValue(record.Fields, _imageUrlField)
                    };

                    var addedTypeId = parent.ProcessRequest<AddOrgUnitTypeResponse>(addTypeRequest).Id;
                    partiallySaved = true;

                    //Add newly created type to OrgUnit
                    var request = new AddOrgUnitOrgUnitTypeRequest()
                    {
                        OrgUnitId = orgUnitId,
                        OrgUnitTypeId = addedTypeId,
                        IsPrimaryOrgUnitType = bool.Parse(parent.GetFieldValue(record.Fields, _isPrimaryOrgUnitTypeField))
                    };

                    parent.ProcessRequest<AddOrgUnitOrgUnitTypeResponse>(request);
                    partiallySaved = true;
                }

                //Deletes
                foreach (var record in orgUnitTypes.Records.Where(r => r.Action == RecordActions.Deleted))
                {
                    var request = new RemoveOrgUnitOrgUnitTypeRequest()
                    {
                        Id = int.Parse(parent.GetFieldValue(record.Fields, _idField))
                    };
                    parent.ProcessRequest<RemoveOrgUnitOrgUnitTypeResponse>(request);
                    partiallySaved = true;
                }
            }
            catch (Exception ex)
            {
                orgUnitTypes.ErrorMessage = ex.Message;

                if (!partiallySaved)
                    throw;
            }

            orgUnitTypes = BuildLocationTypesSubEntity(parent, orgUnitId);
        }
示例#17
0
        private static void AddNewRecordTemplate(LocationAdminDetailView parent, int orgUnitId)
        {
            _subEntity.NewRecordTemplate = new SubEntityRecord()
            {
                Fields =
                {
                    new Field(_idField, "Id", FieldTypes.Hidden, null),
                    new Field(_orgUnitIdField, _orgUnitIdField, FieldTypes.Hidden, orgUnitId)
                }
            };

            _subEntity.NewRecordTemplate.Fields.Add(CommonUtils.CreateDayDropDownField());
            _subEntity.NewRecordTemplate.Fields.Add(new Field("OpenTime", "Open Time", FieldTypes.Text, "8:00 AM"));
            _subEntity.NewRecordTemplate.Fields.Add(new Field("CloseTime", "Close Time", FieldTypes.Text, "5:00 PM"));
        }