public Repository(YourDbContext DbContextScope)     //Intitalizing DBContext
 {
     if (DbContextScope == null)
     {
         throw new ArgumentNullException("DbContextScope");
     }
     _context = DbContextScope.Create();
 }
     public static void SeedRandomPassword(YourDbContext context)
     {
             //// your custom logic to generate random password 
             //// set it to right user
 
             context.Users.Add();  // Or Update depending on what you need
             context.SaveChanges();
         }
Пример #3
0
 public static void Initialize(YourDbContext dbContext)
 {
     dbContext.Database.EnsureCreated();
     if (!dbContext.Users.Any())
     {
         // Write you necessary to code here to insert the User to database and save the the information to file.
     }
 }
Пример #4
0
 public void SaveChanges(UserViewModel user)
 {
     using (var db = new YourDbContext())
     {
         // get user
         // modify and...
         db.SaveChanges();
     }
 }
    public static void InitializeContext()
    {
        Database.SetInitializer(new MigrateDatabaseToLatestVersion <YourDbContext
                                                                    , YourDbContextMigrations>());

        using (var db = new YourDbContext())
        {
            db.Database.Initialize(false);
        }
    }
Пример #6
0
    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        var db = new YourDbContext();

        if (values[parameterName] != null)
        {
            var UsuApelido = values[parameterName].ToString();
            return(db.Plumbers.Any(p => p.Name == UsuApelido));
        }
        return(false);
    }
Пример #7
0
 public IEnumerable <UserViewModel> GetUsers()
 {
     using (var db = new YourDbContext())
     {
         return((
                    from user in db.Users
                    select new UserViewModel
         {
             UserId = user.Id,
             UserName = user.Name,
             GroupId = user.Group.Id,
             GroupName = user.Group.Name,
         }).ToArray());
     }
 }
Пример #8
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (string.IsNullOrEmpty(UserName))
     {
         yield return(new ValidationResult("Username field is required!", new string[] { "UserName" }));
     }
     else
     {
         // check if another User has the same username already
         var db     = new YourDbContext();
         var exists = db.Users.FirstOrDefault(t => t.Id != Id && t.UserName.ToLower() = UserName.ToLower());
         if (exists != null)
         {
             yield return(new ValidationResult("Username is already used by another user!", new string[] { "UserName" }));
         }
     }
 }
    public ActionResult Index()
    {
        var db = new YourDbContext();
        var booksWithChapterList =
            db.Books
            .Include(s => s.chapterLists) //I add chapterList to query, so I don't fetch another query.
            .Select(s => new BookDto      // I convert them to smaller data transfer object.
        {
            Name     = s.Name,
            Chapters = s.chapterLists.Select(w => new BookChapterDto
            {
                Name = w.Name
            }).ToList()
        })
            .ToList();

        return(View(booksWithChapterList));
    }
    //Static method to get an instance of your model when given an userId and DbContext instance. Correct the DbContext type name in the below parameter.
    public static CompanyOverview GetCompanyByUser(int userId, YourDbContext db)
    {
        var qCus = from ad in db.Addresses
                   join ua in db.UsersToAddresses on ad.AddressID equals ua.AddressId
                   join cus in db.CustomerNames on ua.CustomerId equals cus.CustomerId
                   where (ua.UserId == userId)
                   select new CompanyOverview()
        {
            UserId       = userId,
            AddressId    = ad.AddressId,
            CustomerName = cus
        };
        var result = qCus.SingleOrDefault();

        if (result != null)
        {
            result.AddressDetail = db.Addresses.Where(a => a.CustomerId == result.CustomerName.CustomerId)
        }
        return(result);
    }
 public KnowledgeService(YourDbContext db)
 {
     this.db = db;
 }
Пример #12
0
 public YourController(YourDbContext context)
 {
     //.. Assign here and then reuse in controller end points
 }
Пример #13
0
 public ItemRepository(YourDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork)
 {
 }
Пример #14
0
 public MenuViewComponent(YourDbContext context)
 {
     _context = context;
 }
 public YourDomainRepository(YourDbContext context)
 {
     _context = context;
 }
Пример #16
0
 public Repository(YourDbContext dbContext)
 {
     _dbContext = dbContext;
     _dbSet     = _dbContext.Set <TEntity>();
 }
Пример #17
0
 public MyBaseController()
 {
     db = new YourDbContext();
 }
 public UserRepository(YourDbContext yourDbContext) : base(yourDbContext)
 {
 }
 public UnitOfWork(YourDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Пример #20
0
 public MyRepo(YourDbContext ctx)
 {
     dbContext = ctx;
 }
 public CreateModel(YourDbContext context)
 {
     _context = context;
 }
    public virtual decimal DivideOfThisAmountOnAll(YourDbContext db)
    {
        var sum = db.LinqQueryHereToAggregateAsYouPlease.Single();

        return(this.Amount / sum);
    }
 public AdminController()
 {
     db = new YourDbContext();
 }
 public UserRepository(YourDbContext db)
 {
     _db = db;
 }
Пример #25
0
 public GenericRepository(YourDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork)
 {
 }
 public ProductBusinessLogic()
 {
     YourDbContext = new YourDbContext();
 }
Пример #27
0
 public ContactController(YourDbContext db)
 {
     _db = db;
 }