public void ProcessRequest(HttpContext context) { long id = 0; long.TryParse(context.Request.QueryString["id"], out id); if (id > 0) { using (var ec = new EasyContext()) { context.Response.ContentType = "image/jpeg"; var img = Bitmap.FromStream(new MemoryStream(ec.ListingImages.Where(i => i.ID == id).FirstOrDefault().ImageData)); img.Save(context.Response.OutputStream, ImageFormat.Jpeg); } } else { long.TryParse(context.Request.QueryString["shopimageid"], out id); if (id > 0) { using (var ec = new EasyContext()) { context.Response.ContentType = "image/jpeg"; var img = Bitmap.FromStream(new MemoryStream(ec.ShopImages.Where(i => i.ID == id).FirstOrDefault().ImageData)); img.Save(context.Response.OutputStream, ImageFormat.Jpeg); } } } }
protected void RegisterUser_CreatedUser(object sender, EventArgs e) { var user = Membership.GetUser(RegisterUser.UserName); using (var ec = new EasyContext()) { ec.Shops.Add(new Shop() { AccountID = (Guid)user.ProviderUserKey, Name = user.UserName }); ec.SaveChanges(); } try { SendRegistrationEmail(user); }catch { } FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */); string continueUrl = RegisterUser.ContinueDestinationPageUrl; if (String.IsNullOrEmpty(continueUrl)) { continueUrl = "~/"; } Response.Redirect(continueUrl); }
protected void Page_Load(object sender, EventArgs e) { using (var ec = new EasyContext()) { List <char> alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToList(); int columnIndex = 0; HtmlTableCell[] column = new HtmlTableCell[] { col0, col1, col2, col3 }; for (int i = 0; i < alpha.Count; i++) { string a = alpha[i].ToString(); if (ec.Shops.Where(s => s.Name.StartsWith(a)).Count() > 0) { column[columnIndex].InnerHtml += alpha[i] + "<br/>"; ec.Shops .Where(s => s.Name.StartsWith(a)) .ToList() .ForEach(s => column[columnIndex].InnerHtml += "<a href=\"shopdetails.aspx?id=" + s.ID + "\">" + s.Name + "</a><br/>"); columnIndex++; if (columnIndex > 3) { columnIndex = 0; } } } } }
public async Task <ActionResult> Login(VMLogin model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } EasyContext db = new EasyContext(); _store = new UserStore <ApplicationUser>(db); _userManager = new UserManager <ApplicationUser>(this._store); var user = _userManager.Find(model.UserName, model.Password); if (user != null) { await SignInAsync(user, model.RememberMe, db); var role = _userManager.FindById(user.Id).Roles.Select(r => r.RoleId).FirstOrDefault(); role.ToString(); var userRole = db.Database.SqlQuery <UserRole>("SELECT TOP(1) ur.RoleId,r.Name FROM UserRoles AS ur INNER JOIN Roles AS r on r.Id=ur.RoleId WHERE UserId='" + user.Id + "'").FirstOrDefault(); EasySession.RoleId = userRole.RoleId; EasySession.RoleName = userRole.Name; return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", @"Invalid username or password."); return(View(model)); }
private IEnumerable <IdentityRole> _GetRoleList(EasyContext db) { var roleStore = new RoleStore <IdentityRole>(db); var roleMngr = new RoleManager <IdentityRole>(roleStore); var roles = roleMngr.Roles.ToList(); return(roles); }
private async Task SignInAsync(ApplicationUser user, bool isPersistent, EasyContext db) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); _store = new UserStore <ApplicationUser>(db); _userManager = new UserManager <ApplicationUser>(this._store); var identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }
protected void Page_Load(object sender, EventArgs e) { using (var ec = new EasyContext()) { categoryListing.DataSource = ec.Categories .Where(c => c.ListingItems.Where(i => !i.IsSold).Count() > 0) .OrderBy(c => c.Name) .Select(c => new { ID = c.ID, Name = c.Name, Count = c.ListingItems.Where(i => !i.IsSold).Count() }).ToList(); categoryListing.DataBind(); featuredListing.DataSource = ec.ListingItems .Where(i => i.IsFeatured && i.IsSold == false && i.Images.Count > 0) .OrderByDescending(i => i.CreatedOn) .Take(4) .Select(i => new { ID = i.ID, Title = i.Title, Price = i.Price, ImageID = i.Images.FirstOrDefault().ID }) .ToList(); featuredListing.DataBind(); featuredContainer.Visible = featuredListing.Items.Count > 0; } }
public KnowledgesController(EasyContext context) { _context = context; }
public UserRepository(DbContext context) : base(context) { _context = (EasyContext)context; }
static void Main(string[] args) { /* * SQL FOR REFERENCE * * USE SimpleCodeFirst; * * IF Object_id('ProductOrder') IS NOT NULL * DROP TABLE ProductOrder * * IF Object_id('Product') IS NOT NULL * DROP TABLE Product * * IF Object_id('Person') IS NOT NULL * DROP TABLE Person * * CREATE TABLE Person * ( * PersonId int identity CONSTRAINT PK_PersonId PRIMARY Key * , FirstName varchar(256) NOT NULL * , LastName varchar(256) NOT NULL * ) * * CREATE TABLE ProductOrder * ( * ProductOrderId int identity NOT NULL CONSTRAINT PK_ProductOrderId PRIMARY Key * , PersonId int CONSTRAINT FK_ProductOrder_PersonId FOREIGN Key(PersonId) REFERENCES Person(PersonId) * , OrderName varchar(256) NOT NULL * ) * * CREATE TABLE Product * ( * ProductId int IDENTITY CONSTRAINT PK_ProductId PRIMARY Key * , OrderId int CONSTRAINT FK_Product_OrderId FOREIGN Key(OrderId) REFERENCES Order(OrderId) * , ProductName varchar(256) NOT NULL * ) * * INSERT INTO dbo.Person(FirstName, LastName) VALUES('Bart', 'Simpson'),('Lisa', 'Simpson'); * INSERT INTO dbo.ProductOrder(PersonId, OrderName) VALUES (1, 'Clothing'),(2, 'Clothing'),(1, 'SpareTime'); * INSERT INTO dbo.Product(OrderId, ProductName) VALUES(1, 'Shirt'),(1, 'Shoes'),(1, 'Shorts'),(1, 'Hat'),(2, 'Dress'),(2, 'Bow'),(3, 'SkateBoard'); * * Select * p.FirstName + ' ' + p.LastName AS Name * , po.OfficeName * , o.ProductName * from dbo.Person p * left JOIN dbo.Order o ON o.PersonId = p.PersonId * left JOIN dbo.Product po ON po.OrderId = o.OrderId * * TO ENABLE AUTOMATIC MIGRATION: * First, open the package manager console from Tools → Library Package Manager → Package Manager Console and then * run "enable-migrations –EnableAutomaticMigration:$true" command * (make sure that the default project is the project where your context class is) * * TO ENABLE ADD MIGRATION: * First, open the package manager console from Tools → Library Package Manager → Package Manager Console and then * run "add-migration "First Easy schema"" or similar. * * UPDATE DATABASE AFTER MIGRATION: * First, open the package manager console from Tools → Library Package Manager → Package Manager Console and then * run "update-database -verbose". The verbose switch will show the SQL Statements that run as well. * * FORCE DATABASE FORCE: * */ using (var context = new EasyContext()) { //var people = context.Person.ToList(); //people.ForEach(x => Console.WriteLine($"{x.PersonId} {x.FirstName} {x.OverlyLongDescriptionField}")); var productOrders = context.ProductOrder.Include("Products").ToList(); var persons = context.Person.ToList(); persons.GroupJoin(productOrders, p => p.PersonId, o => o.Person.PersonId, (p, g) => g .Select(o => new { PersonId = p.PersonId, PersonName = p.FirstName + " " + p.LastName, p.OverlyLongDescriptionField, Orders = o }) .DefaultIfEmpty(new { PersonId = p.PersonId, PersonName = p.FirstName + " " + p.LastName, p.OverlyLongDescriptionField, Orders = new ProductOrder() }) ) .SelectMany(g => g) .ToList() .ForEach(item => { Console.WriteLine($"{item.PersonId}: {item.PersonName}: {item.OverlyLongDescriptionField}"); if (!(item?.Orders?.Products?.Count > 0)) { return; } Console.WriteLine($"\t {item.Orders.ProductOrderId}: {item.Orders.ProductOrderName}"); item.Orders.Products.ToList().ForEach(x => Console.WriteLine($"\t\t{x.ProductId}: {x.ProductName}")); }); Console.ReadLine(); } }
internal EasyQueryable(EasyContext context) { _context = context; }
public UnityOfWork(EasyContext banco) { _banco = banco; }
public Repositorio(EasyContext banco) { _dbSet = banco.Set <TEntity>(); }
public CandidatesController(EasyContext context) { _context = context; }
protected override void Seed(EasyContext context) { SeedingValues.SeedingWithoutDatabaseDrop(context); base.Seed(context); }