Ejemplo n.º 1
0
        private static void AddCharacterInPlot(ConscienceContext context, Dictionary <string, Plot> plots, IRow row, Character character, int plotColumn)
        {
            var plotCode = row.GetCell(plotColumn).ToCleanString().Trim();

            if (string.IsNullOrWhiteSpace(plotCode))
            {
                return;
            }

            var plotFunction = row.GetCell(plotColumn + 3).ToCleanString().Trim();
            var hasEvent     = row.GetCell(plotColumn + 4).ToCleanString().Trim().ToLowerInvariant() == "yes";

            if (!plots.ContainsKey(plotCode))
            {
                throw new Exception("There is no plot with code " + plotCode);
            }

            var plot = plots[plotCode];

            character.Plots.Add(new CharacterInPlot
            {
                Description = plotFunction,
                Plot        = plot
            });

            if (hasEvent)
            {
                plot.Events.First().Characters.Add(character);
            }

            context.SaveChanges();
        }
Ejemplo n.º 2
0
        private void ClearSet <T>(ConscienceContext context, DbSet <T> set, Expression <Func <T, bool> > excludePredicate = null) where T : class
        {
            List <T> values = null;

            if (excludePredicate != null)
            {
                values = set.Where(excludePredicate).ToList();
            }
            else
            {
                values = set.ToList();
            }

            foreach (var value in values)
            {
                set.Remove(value);
            }

            context.SaveChanges();
        }
Ejemplo n.º 3
0
        private void ClearDb(ConscienceContext context, ConscienceAccount currentUser)
        {
            var roles = currentUser.Roles.ToList();

#if DEBUG
            context.Database.Delete();
            context.Database.Create();

            var account = new ConscienceAccount
            {
                UserName     = currentUser.UserName,
                PasswordHash = currentUser.PasswordHash
            };
            context.Accounts.Add(account);
            foreach (var role in roles)
            {
                account.Roles.Add(new Role {
                    Name = role.Name
                });
            }
            context.SaveChanges();
#endif
        }
Ejemplo n.º 4
0
        private static void AddRelation(ConscienceContext context, BulkImportResult result, Dictionary <int, Character> characters, IRow row, Character character, string hostName, int relationColumn)
        {
            if (row.GetCell(relationColumn) == null)
            {
                return;
            }

            var relation = row.GetCell(relationColumn).ToCleanString().Trim();

            if (string.IsNullOrWhiteSpace(relation))
            {
                return;
            }

            var reader      = new StringReader(relation);
            var name        = reader.ReadLine().Trim();
            var description = reader.ReadToEnd();

            var relatedCharacter = characters.Values.FirstOrDefault(c => c.Name.ToLowerInvariant() == name.ToLowerInvariant());

            if (relatedCharacter == null)
            {
                result.Errors.Add(new BulkImportError {
                    Line = "Characrer relations - " + hostName, Error = "There is no character with name " + name
                });
                return;
            }

            character.Relations.Add(new CharacterRelation
            {
                Character   = relatedCharacter,
                Description = description
            });

            context.SaveChanges();
        }
Ejemplo n.º 5
0
 public CharacterRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 6
0
 public PlotRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 7
0
 public ApplicationUserStore(ConscienceContext context, RoleRepository rolesRepo, AccountRepository accountsRepo)
 {
     _context      = context;
     _rolesRepo    = rolesRepo;
     _accountsRepo = accountsRepo;
 }
Ejemplo n.º 8
0
 public AudioRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 9
0
 public NotificationRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 10
0
 public AccountRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 11
0
 public EmployeeRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 12
0
 public RoleRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 13
0
        private static async Task <ConscienceAccount> CreateOrUpdateAccount(IUsersIdentityService identityService, ConscienceContext context, string name, string password, string role)
        {
            var account = context.Accounts.FirstOrDefault(a => a.UserName.ToLower() == name.ToLower());

            if (account == null)
            {
                account = new ConscienceAccount
                {
                    UserName     = name,
                    PasswordHash = "AA+JyvawjlityY0fyaRSr1qZkCgaIvU+bqTe6uShANUqcoG0EH2F6BcXq7hwnN7N1Q=="
                };
                var roleName = Enum.GetNames(typeof(RoleTypes)).First(r => r.ToLowerInvariant() == role.ToLowerInvariant());
                account.Roles.Add(new Role
                {
                    Name = roleName
                });
                context.Accounts.Add(account);
                context.SaveChanges();
            }

            account.PictureUrl = "/Content/images/uploaded/" + account.Id + ".jpg?_ts=101";
            context.SaveChanges();

            await identityService.ChangePasswordAsync(account.Id, password);

            return(account);
        }
Ejemplo n.º 14
0
 public DeviceRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 15
0
 public MemoryRepository(ConscienceContext context) : base(context)
 {
 }
Ejemplo n.º 16
0
 public BaseRepository(ConscienceContext context)
 {
     _context = context;
 }