public void Given_BasicTypeSetting_When_IsValid_Then_SettingRetrieved()
        {
            var context = this.Fixture.GetContext <ConfigurationContext>();

            var section = new SectionEntity()
            {
                ApplicationName = "EFConfigurationProviderTests", SectionName = "appSettings", Aspect = "Application", ModifiedUser = "******"
            };

            context.Sections.Add(section);
            context.SaveChanges();

            var setting = new SettingEntity()
            {
                SectionId = section.Id, Key = "TestSetting", Json = @"Test Value", ModifiedUser = "******"
            };

            setting.ValueType = null;

            context.Settings.Add(setting);
            context.SaveChanges();

            this.Fixture.ClearChangeTracker();

            var builder       = new ConfigurationBuilder().AddEntityFrameworkConfig(context, "EFConfigurationProviderTests");
            var configuration = builder.Build();

            var value = configuration.GetValue <string>("TestSetting");

            Assert.True(value == "Test Value");
        }
Esempio n. 2
0
        public static Section ToSection(this SectionEntity section, IList <string> languages, bool addFields = true)
        {
            var orderedSections = section.Form.Sections
                                  .Where(s => s.DateDeleted == null)
                                  .OrderBy(s => s.DisplaySort)
                                  .ToList();
            var index = orderedSections.IndexOf(section);

            return(new Section
            {
                Id = section.Id,
                NextSectionId = index == orderedSections.Count - 1 ? null : (int?)orderedSections[index + 1].Id,
                PreviousSectionId = index == 0 ? null : (int?)orderedSections[index - 1].Id,
                FormId = section.FormId,
                Label = section.Resource.ToLabel(languages),
                Labels = section.Resource.ToLabels(languages),
                Fields =
                    addFields
                    ? section.SectionFields
                    .Where(sf => sf.DateDeleted == null)
                    .OrderBy(sf => sf.DisplaySort)
                    .Select(sf => sf.Field.ToField(languages))
                    .ToList()
                    : null
            });
        }
        public IActionResult GetAsignacionesFromSection(int id)
        {
            try
            {
                //Comprueba si existe asignación y si existe manda un json con la información
                //si no existe mandara un error 404 el error 500 aparecera si el servidor falla
                SectionEntity sectionExist = _sectionInfoRepository.GetSection(id, true);
                if (sectionExist == null)
                {
                    _logger.LogInformation($"La section con id " + id + " no pudo ser encontrado.");
                    return(NotFound());
                }

                //Recogemos una lista de preguntas de la asignacion
                var asignacionesDeSection = _sectionInfoRepository.GetAsignacionesFromSection(sectionExist);

                //Transformamos la lista anterior en una nueva con los datos que necesitamos
                //Ya que otros son relevantes
                var AsignacionesResult = Mapper.Map <IEnumerable <AsignacionDto> >(asignacionesDeSection);
                return(Ok(AsignacionesResult));
            }
            catch (Exception ex)
            {
                _logger.LogCritical("Se recogio un error al recibir las asignaciones de la section con id " + id + ": " + ex);
                return(StatusCode(500, "Un error a ocurrido mientras se procesaba su petición."));
            }
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">The primary key or id of the <see cref="SectionEntity"/></param>
        /// <param name="user">The <see cref="UserEntity"/>.</param>
        /// <param name="entity"></param>
        /// <returns></returns>
        private SectionEntity GetUserSection(int id, UserEntity user)
        {
            SectionEntity entity = null;

            // Try to found section in dependencies.
            foreach (UsersInAclGroups group in user.UsersInAclGroups)
            {
                IQueryable <AclGroupEntity> groups = Connector.AclGroups;
                groups = groups.Include(x => x.SectionsInAclGroups);
                AclGroupEntity ag = groups.SingleOrDefault(x => x.PrimaryKey == group.AclGroupId);

                if (ag.PrimaryKey == 0 || ag.SectionsInAclGroups.Count == 0)
                {
                    continue;
                }

                var dep = ag.SectionsInAclGroups.ToList().Find(x => x.SectionId == id);

                if (dep != null)
                {
                    IQueryable <SectionEntity> sections = Connector.Sections;
                    sections = sections.Include(x => x.SectionsInAclGroups);
                    sections = sections.Include(x => x.AlbumsInSections);

                    entity = sections.SingleOrDefault(x => x.PrimaryKey == id);
                }

                if (entity?.PrimaryKey > 0)
                {
                    break;
                }
            }

            return(entity);
        }
        public void Given_BasicTypeSettingWithDescriminator_When_MultiDescriminatorIsValid_Then_SettingRetrieved()
        {
            var context = this.Fixture.GetContext <ConfigurationContext>();

            var section = new SectionEntity()
            {
                ApplicationName = "EFConfigurationProviderTests", SectionName = "appSettings2", Aspect = "Application", Discriminator = @"{""Environment"":""Testing"", ""Username"":""Patrick""}", ModifiedUser = "******"
            };

            context.Sections.Add(section);
            context.SaveChanges();

            var setting = new SettingEntity()
            {
                SectionId = section.Id, Key = "TestSetting2", Json = @"Test Value", ModifiedUser = "******"
            };

            setting.ValueType = null;

            context.Settings.Add(setting);
            context.SaveChanges();

            this.Fixture.ClearChangeTracker();

            var builder       = new ConfigurationBuilder().AddEntityFrameworkConfig(context, "EFConfigurationProviderTests", @"{""Environment"":""Testing"", ""Username"":""Patrick""}");
            var configuration = builder.Build();

            var value = configuration.GetValue <string>("TestSetting2");

            Assert.True(value == "Test Value");
        }
        /// <summary>
        /// This function is used to delete an SectionEntity.
        /// </summary>
        /// <param name="uid">Unique ID</param>
        /// <returns>True on success, false on fail.</returns>
        public static bool Delete(System.Int32 uid)
        {
            SectionEntity     section = new SectionEntity(uid);
            DataAccessAdapter ds      = new DataAccessAdapter();

            return(ds.DeleteEntity(section));
        }
        public void Given_AddSetting_When_ValueIsComplexTypeWithNoValueType_Then_SettingIsPersistedAndValueAsJObjectReturned()
        {
            var context = this.Fixture.GetContext <ConfigurationContext>();

            var section = new SectionEntity()
            {
                ApplicationName = "DbContextSettingTests", SectionName = "TestSection2", ModifiedUser = "******"
            };

            context.Sections.Add(section);
            context.SaveChanges();

            var setting = new SettingEntity()
            {
                SectionId = section.Id, Key = "default", ModifiedUser = "******"
            };

            setting.SetValue(new TestSection()
            {
                Id = Guid.NewGuid(), Name = "Test"
            });
            setting.ValueType = null;
            context.Settings.Add(setting);
            context.SaveChanges();

            var retrieved = context.Settings.AsNoTracking().FirstOrDefault(s => s.SectionId == section.Id && s.Key == "default");

            Assert.NotNull(retrieved);
            Assert.NotNull(retrieved.GetValue <JObject>());
        }
        public void Given_AddSetting_When_SettingIsDuplicate_Then_SettingNotPersisted()
        {
            this.Fixture.ClearAll();
            var section = new SectionEntity()
            {
                ApplicationName = "DbContextSettingTests", SectionName = "appSettingsB", ModifiedUser = "******"
            };

            this.Fixture.Context.Sections.Add(section);
            this.Fixture.Context.SaveChanges();

            var exception = Assert.Throws <DbUpdateException>(() =>
            {
                this.Fixture.Context.Settings.Add(new SettingEntity()
                {
                    SectionId = section.Id, Key = "SettingA", ModifiedUser = "******"
                });
                this.Fixture.Context.Settings.Add(new SettingEntity()
                {
                    SectionId = section.Id, Key = "SettingA", ModifiedUser = "******"
                });
                this.Fixture.Context.SaveChanges();
            });

            Assert.True(exception.InnerException != null && exception.InnerException.Message.StartsWith("Cannot insert duplicate key row in object 'Configuration.Setting' with unique index 'IX_Setting_SectionId_Key'"));
        }
Esempio n. 9
0
        /// <summary>
        /// Method to update a Section entity asynchronously.
        /// </summary>
        /// <param name="entity">A Section entity.</param>
        /// <param name="save">Save database changes ?</param>
        /// <returns>The updated <see cref="SectionEntity"/>.</returns>
        public async Task <SectionEntity> UpdateAsync(SectionEntity entity, bool save = true)
        {
            using (Db.Context)
            {
                // Try to attach entity to the database context.
                try
                {
                    Db.Context.Attach(entity);
                }
                catch (Exception e)
                {
                    log.Fatal(e.Output(), e);
                    throw e;
                }

                // Update entity.
                entity = await SectionManager.UpdateAsync(entity);

                // Check if entity is set to default.
                if (entity.IsDefault)
                {
                    await SetDefaultAsync(entity.PrimaryKey);
                }

                // Hack to delete unassociated dependencies.
                //await CleanDependenciesAsync("SectionsInACLGroups", "AclGroupId", entity.PrimaryKey, entity.AclGroupsPKeys);
                //await CleanDependenciesAsync("AlbumsInSections", "AlbumId", entity.PrimaryKey, entity.AlbumsPKeys);

                return(entity);
            }
        }
        public void Given_AddSetting_When_ValueIsComplexType_Then_SettingIsPersisted()
        {
            this.Fixture.ClearAll();
            var section = new SectionEntity()
            {
                ApplicationName = "DbContextSettingTests", SectionName = "TestSection1", ModifiedUser = "******"
            };

            this.Fixture.Context.Sections.Add(section);
            this.Fixture.Context.SaveChanges();

            var setting = new SettingEntity()
            {
                SectionId = section.Id, Key = "default", ModifiedUser = "******"
            };

            setting.SetValue(new TestSection()
            {
                Id = Guid.NewGuid(), Name = "Test"
            });
            this.Fixture.Context.Settings.Add(setting);
            this.Fixture.Context.SaveChanges();

            var retrieved = this.Fixture.Context.Settings.FirstOrDefault(s => s.SectionId == section.Id && s.Key == "default");

            Assert.NotNull(retrieved);
            Assert.NotNull(retrieved.GetValue <TestSection>());
        }
Esempio n. 11
0
        public Database SeedSectionWithChild()
        {
            using (var context = new ConfigurationContext())
            {
                var complex = new SectionWithChild()
                {
                    Id    = Guid.NewGuid(),
                    Name  = "parent",
                    Child = new Child()
                    {
                        Id   = Guid.NewGuid(),
                        Name = "child"
                    }
                };

                var section = new SectionEntity()
                {
                    ApplicationName = "SampleApplication", Aspect = "settings", SectionName = "SectionWithChild"
                };
                context.Sections.Add(section);
                context.SaveChanges();

                var setting = new SettingEntity()
                {
                    SectionId = section.Id, Key = "SectionWithChild"
                };
                setting.SetValue(complex);

                context.Settings.Add(setting);
                context.SaveChanges();
            }
            return(this);
        }
Esempio n. 12
0
        /// <summary>
        /// Method called on <see cref="SectionEntity"/> default change event.
        /// </summary>
        /// <param name="sender">The <see cref="object"/> sender of the event.</param>
        /// <param name="e">Entity changes event arguments <see cref="EntityChangesEventArgs"/>.</param>
        private void SectionsDataGrid_DefaultChanged(object sender, EntityChangesEventArgs e)
        {
            try
            {
                MessageBoxs.IsBusy = true;
                log.Warn("Setting default Section. Please wait...");

                SectionEntity newEntity = (SectionEntity)e.NewEntity;
                SectionEntityCollection.SetDefault(newEntity);
                Model.LoadSections();

                log.Warn("Setting default Section. Done.");
            }

            catch (Exception ex)
            {
                log.Fatal(ex.Output(), ex);
                MessageBoxs.Fatal(ex, "Setting default Section. Fail.");
            }

            finally
            {
                MessageBoxs.IsBusy = false;
            }
        }
Esempio n. 13
0
 public static SectionEntity AddSection(this FormEntity form, SectionEntity section)
 {
     section.Form   = form;
     section.FormId = form.Id;
     form.Sections.Add(section);
     return(section);
 }
Esempio n. 14
0
        public ActionResult LotRows(string sectionName = null, string categoryName = null)
        {
            IList <LotRowViewModel> lots = new List <LotRowViewModel>();

            if (categoryName == null)
            {
                SectionEntity section = _sectionService.GetAllSectionEntities().FirstOrDefault(s => s.SectionName == sectionName);
                if (section != null)
                {
                    foreach (var category in section.Categories)
                    {
                        var lotsTemp = _lotService.GetAllLotEntities()
                                       .Where(l => l.CategoryRefId == category.Id).Where(l => !l.IsBlocked && l.IsConfirm).ToList();
                        foreach (var l in lotsTemp)
                        {
                            lots.Add(l.ToLotRowViewModel());
                        }
                    }
                }
            }
            else
            {
                lots = _lotService.GetAllLotEntities().Where(l => l.CategoryName == categoryName && !l.IsBlocked && l.IsConfirm)
                       .Select(l => l.ToLotRowViewModel())
                       .ToList();
            }
            return(PartialView("_LotRows", lots));
        }
Esempio n. 15
0
 public static DalSection ToDalSection(this SectionEntity sectionEntity)
 {
     return(new DalSection()
     {
         Id = sectionEntity.Id,
         Name = sectionEntity.SectionName,
     });
 }
Esempio n. 16
0
        /// <summary>Creates a new, empty SectionEntity object.</summary>
        /// <returns>A new, empty SectionEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new SectionEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewSection
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
Esempio n. 17
0
        public async Task <SectionEntity> Add(SectionEntity pEntity)
        {
            await this.dbContext.SalonSections.AddAsync(pEntity);

            await this.dbContext.SaveChangesAsync();

            return(pEntity);
        }
        //Nos permite modificar una section
        public bool AlterSection(SectionEntity section)
        {
            var SectionAlter = _context.Sections.Where(s => s.Id == section.Id).FirstOrDefault();

            SectionAlter.Nombre = section.Nombre;

            return(SaveChanges());
        }
Esempio n. 19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var secId = int.Parse(Request.QueryString["secId"]);

            var section = SectionEntity.GetSection(secId);
            var mClass  = ClassEntity.GetClass(section.ClassId);

            this.threadHeader.Text = mClass.ClassName + " - " + section.SectionName;
        }
Esempio n. 20
0
        public ActionResult Section()
        {
            SectionEntity sectionEntity = new SectionEntity();

            sectionEntity.operType  = 'G';
            sectionEntity.reportId  = "4";
            TempData["SectionData"] = new Master().SectionDetails(sectionEntity);
            return(PartialView());
        }
Esempio n. 21
0
        private bool SectionTypeMatches(SectionEntity sectionEntity, string pSectionTypeCode)
        {
            if (pSectionTypeCode == null)
            {
                return(true);
            }

            return(sectionEntity.SectionType.SectionCode == pSectionTypeCode);
        }
Esempio n. 22
0
        public Result Insert(SectionEntity entity)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                var linkEntity = new LinkEntity
                {
                    Href   = " ",
                    Name   = entity.Title,
                    Type   = "SECTION",
                    Active = false
                };

                query.Entity = linkEntity;
                query.Query  = @"INSERT INTO Links (Name, Type, Href, Active) VALUES(@Name, @Type, @Href, @Active)";


                result = con.InsertQueryUnScoped(query);
                if (!result.Success)
                {
                    return(result);
                }
                var linkId = (int)result.Entity;

                entity.LinkId = linkId;
                query.Entity  = entity;
                query.Query   = @"INSERT INTO Sections (Name, Title, Sealed, Published, LinkId) VALUES(@Name, @Title, @Sealed, @Published, @LinkId)";
                result        = con.InsertQueryUnScoped(query);

                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }

                //LINK HREF UPDATE
                var queryUpdateLink = new QueryEntity()
                {
                    Entity = new { Href = "/sections/" + (int)result.Entity, LinkId = linkId },
                    Query  = "UPDATE Links set Href = @Href where LinkId = @LinkId"
                };
                var resultUpdateLink = con.ExecuteQueryUnScoped(queryUpdateLink);
                if (!resultUpdateLink.Success)
                {
                    result.Message = "An error occurred";
                    result.Success = false;
                    return(result);
                }

                scope.Complete();
            }
            result.Message = "The section has been created";
            return(result);
        }
Esempio n. 23
0
        public Result Get(int id)
        {
            var con   = new DapperConnectionManager();
            var query = new QueryEntity();

            query.Query  = @"SELECT s.SectionId, s.Name as SectionName, s.Title as SectionTitle,
                                   c.Name, c.Title, c.Type, c.ContentItemId, c.Position, c.Text from Sections as s
                            LEFT JOIN ContentItems as c
                            on s.SectionId = c.SectionId
                            where s.SectionId = @SectionId
                            ORDER BY c.Position ASC";
            query.Entity = new { SectionId = id };

            var result = con.ExecuteQuery(query);

            if (!result.Success)
            {
                result.Message = "Section not found";
                return(result);
            }
            var r = (IEnumerable <dynamic>)result.Entity;

            if (!r.Any())
            {
                return(result);
            }

            var sectionEntity = new SectionEntity();

            sectionEntity.SectionId    = r.First().SectionId;
            sectionEntity.Name         = r.First().SectionName;
            sectionEntity.Title        = r.First().SectionTitle;
            sectionEntity.ContentItems = new List <ContentItemEntity>();
            foreach (var item in r)
            {
                if (item.ContentItemId == null)
                {
                    continue;
                }
                var contentItem = new ContentItemEntity
                {
                    Name          = item.Name,
                    ContentItemId = item.ContentItemId,
                    Text          = item.Text,
                    Position      = item.Position,
                    Type          = item.Type,
                    SectionId     = item.SectionId,
                    Title         = item.Title,
                    TextShort     = (item.Text as string ?? string.Empty).Truncate()
                };

                sectionEntity.ContentItems.Add(contentItem);
            }
            result.Entity = sectionEntity;
            return(result);
        }
Esempio n. 24
0
        private SectionEntity Get(int id)
        {
            SectionEntity entity = null;

            if (id > 0)
            {
                entity = Sections.FirstOrDefault(x => x.Id == id && !x.IsDefault);
            }

            return(entity);
        }
Esempio n. 25
0
        /// <summary>
        /// Gets the section entity of the id passed in
        /// </summary>
        /// <param name="sectionID">The section ID.</param>
        /// <returns>loaded sectionentity or null if not found</returns>
        public static SectionEntity GetSection(int sectionID)
        {
            SectionEntity toReturn = new SectionEntity(sectionID);

            if (toReturn.IsNew)
            {
                // not found
                return(null);
            }
            return(toReturn);
        }
Esempio n. 26
0
 public static SectionCreateViewModel ToSectionViewModel(this SectionEntity entity)
 {
     return(new SectionCreateViewModel()
     {
         UserRefId = entity.UserRefId,
         SectionName = entity.SectionName,
         Discription = entity.Discription,
         SettedModeratorLogin = entity.ModeratorLogin,
         Id = entity.Id
     });
 }
        public void Given_ComplexTypeSectionWithChildren_When_IsValid_Then_SectionRetrieved()
        {
            var context = this.Fixture.GetContext <ConfigurationContext>();

            var section = new SectionEntity()
            {
                ApplicationName = "EFConfigurationProviderTests", SectionName = "TestSection3", Aspect = "Application", ModifiedUser = "******"
            };

            context.Sections.Add(section);
            context.SaveChanges();

            var value = new TestSectionWithChildren()
            {
                Id   = Guid.NewGuid(),
                Name = "Test1"
            };

            value.Children = new Collection <TestSectionChild>();
            value.Children.Add
            (
                new TestSectionChild()
            {
                Id   = Guid.NewGuid(),
                Name = "Test1"
            }
            );

            var setting = new SettingEntity()
            {
                SectionId    = section.Id,
                Key          = "default",
                ModifiedUser = "******"
            };

            setting.SetValue(value);
            context.Settings.Add(setting);
            context.SaveChanges();

            this.Fixture.ClearChangeTracker();

            var builder       = new ConfigurationBuilder().AddEntityFrameworkConfig(context);
            var configuration = builder.Build();

            var configSection = configuration.GetSection <TestSectionWithChildren>("TestSection3", false);

            Assert.NotNull(configSection);
            Assert.NotNull(configSection.Children);
            var child = configSection.Children.FirstOrDefault();

            Assert.NotNull(child);
            Assert.Equal(value.Children.First().Id, child.Id);
            Assert.Equal(value.Children.First().Name, child.Name);
        }
Esempio n. 28
0
 public static DalSection ToDalSection(this SectionEntity sectionEntity)
 {
     if (sectionEntity != null)
     {
         return(new DalSection()
         {
             Id = sectionEntity.Id,
             Name = sectionEntity.Name
         });
     }
     return(null);
 }
 public void DeleteSection(SectionEntity entity)
 {
     try
     {
         _sectionReposytory.Delete(entity.ToDalSection());
         _unitOfWorkuow.Commit();
     }
     catch (Exception e)
     {
         Log.LogError(e);
     }
 }
Esempio n. 30
0
 public static SectionModel ToModelSection(this SectionEntity entity)
 {
     if (entity != null)
     {
         return(new SectionModel()
         {
             Id = entity.Id,
             Name = entity.Name
         });
     }
     return(null);
 }