コード例 #1
0
 public Repository(YourDbContext DbContextScope)     //Intitalizing DBContext
 {
     if (DbContextScope == null)
     {
         throw new ArgumentNullException("DbContextScope");
     }
     _context = DbContextScope.Create();
 }
コード例 #2
0
     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();
     }
 }
コード例 #5
0
    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" }));
         }
     }
 }
コード例 #9
0
    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));
    }
コード例 #10
0
    //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);
    }
コード例 #11
0
 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;
 }
コード例 #15
0
 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();
 }
コード例 #18
0
 public UserRepository(YourDbContext yourDbContext) : base(yourDbContext)
 {
 }
コード例 #19
0
 public UnitOfWork(YourDbContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #20
0
 public MyRepo(YourDbContext ctx)
 {
     dbContext = ctx;
 }
コード例 #21
0
 public CreateModel(YourDbContext context)
 {
     _context = context;
 }
コード例 #22
0
    public virtual decimal DivideOfThisAmountOnAll(YourDbContext db)
    {
        var sum = db.LinqQueryHereToAggregateAsYouPlease.Single();

        return(this.Amount / sum);
    }
コード例 #23
0
 public AdminController()
 {
     db = new YourDbContext();
 }
コード例 #24
0
 public UserRepository(YourDbContext db)
 {
     _db = db;
 }
コード例 #25
0
 public GenericRepository(YourDbContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork)
 {
 }
コード例 #26
0
 public ProductBusinessLogic()
 {
     YourDbContext = new YourDbContext();
 }
コード例 #27
0
 public ContactController(YourDbContext db)
 {
     _db = db;
 }