public ActionResult NotFound() { using (var db = new DealContext()) { var d = db.ActiveDeals.OrderByDescending(x => x.AddedDate).Take(20).ToList(); return(View(d)); } }
public async Task SaveDeal(Deal deal) { using (var db = new DealContext()) { db.Add(deal); await db.SaveChangesAsync(); } }
public async Task <bool> IsDealNew(Deal deal) { using (var db = new DealContext()) { // for now use Url as unique identifier. There are probably better ways to detect uniqueness even scraping return(!await db.Deals.AnyAsync(d => d.Url == deal.Url)); } }
public void TestMethod1() { using (var db = new DealContext()) { var deals = db.ActiveDeals.ToList(); Assert.IsTrue(deals.Any()); } }
public ActionResult Partners(string slug) { ViewBag.Partner = slug.Humanize(LetterCasing.Title); ViewBag.Title = ViewBag.Partner; using (var db = new DealContext()) { var deals = db.PartnerDeals.Where(x => x.PartnerSlug.Equals(slug)).ToList(); return(View(deals)); } }
public ActionResult Register(RegisterModel model) { if (!model.Username.IsValidEmail()) { ModelState.AddModelError(string.Empty, "Invalid email address!"); return(View());//"Register"); } if (string.IsNullOrEmpty(model.Name)) { ModelState.AddModelError(string.Empty, "Please enter a name!"); return(View());//RedirectToAction("Register"); } if (string.IsNullOrEmpty(model.Password) || model.Password.Length < 6) { ModelState.AddModelError(string.Empty, "Password must be at least 6 charachters long!"); return(View());//RedirectToAction("Register"); } using (var db = new DealContext()) { var user = db.Users.FirstOrDefault( x => x.Username.ToLower() == model.Username.ToLower()); if (user != null) { ModelState.AddModelError(string.Empty, "User email already registerd!"); return(View());//RedirectToAction("Register"); } var u = new DfUser(); u.Username = model.Username; u.Password = model.Password; u.FirstName = model.Name; u.LastName = ""; u.UserEmail = model.Username; u.AuthCode = ""; u.Title = ""; u.CityId = 0; u.MobileNo = ""; u.AgeGroup = ""; u.UserGender = ""; u.DateCreated = DateTime.UtcNow; u.UserActive = true; db.Users.Add(u); db.SaveChanges(); FormsAuthentication.SetAuthCookie(model.Username, false); return(Redirect("/")); } }
public void DealController_GetDealTestCase() { DealContext dbContext = LoadDependencies <DealContext>(); var mockRepo = new DealRepository(dbContext); var logger = new FlatFileLogger(); var controller = new DealController(mockRepo, logger); var result = controller.GetDealsByCountryId(1); Assert.NotNull(result); var deal = Assert.IsAssignableFrom <Deal>((result as OkObjectResult).Value as Deal); Assert.Equal(1, deal.country_id); }
public void DealController_GetAllTestCase() { DealContext dbContext = LoadDependencies <DealContext>(); var mockRepo = new DealRepository(dbContext); var logger = new FlatFileLogger(); var controller = new DealController(mockRepo, logger); var result = controller.Get(); Assert.NotNull(result); var lstDeal = Assert.IsAssignableFrom <IList <Deal> >((result as OkObjectResult).Value as IList <Deal>); Assert.Equal(2, lstDeal.Count); }
public ActionResult Login(LoginModel model) { using (var db = new DealContext()) { var user = db.Users.FirstOrDefault( x => x.Username.ToLower() == model.Username.ToLower() && x.Password == model.Password); if (user != null) { FormsAuthentication.SetAuthCookie(model.Username, false); return(Redirect("/")); } ModelState.AddModelError(string.Empty, "Invalid Login"); return(RedirectToAction("Login")); } }
public ActionResult Search(string q) { var query = HttpUtility.UrlDecode(q);//Request.QueryString["q"]; if (string.IsNullOrEmpty(query)) { return(RedirectToAction("Index")); } ViewBag.Category = string.Format("Search for: {0}", query); ViewBag.Title = ViewBag.Category; using (var db = new DealContext()) { var deals = db.ActiveDeals.Where(x => x.Title.Contains(query)).ToList(); return(View(deals)); } }
public ActionResult Category(string cat) { ViewBag.Category = cat.Humanize(LetterCasing.Title); ViewBag.Title = cat.Humanize(LetterCasing.Title); using (var db = new DealContext()) { if (cat.ToLower() == "top") { var d = db.ActiveDeals.OrderByDescending(x => x.AddedDate).Take(20).ToList(); return(View(d)); } var deals = db.ActiveDeals.Where(x => x.CatSlug.Equals(cat)).ToList(); return(View(deals)); } }
/// <summary> Initializes the DB Context. </summary> /// <param name="context"> The DB Context to initialize. </param> public static void InitializeContext(DealContext context) { context.Database.EnsureCreated(); //* Use during development, then get rid of this in favor of Migrations if (context.Deal.Any()) { return; // DB has been seeded } var units = new Unit[] { new Unit { CustomerName = "Test, Bob", AppraiserName = "Appraiser, Jim", CustomerAddress = "100 Pigkicker Ln", ModelYear = 1999, VIN = "1M3P272K1XM001040" } }; var deals = new Deal[] { new Deal { } }; foreach (var deal in deals) { deal.UpdateAuditFields(1); } foreach (var unit in units) { unit.UpdateAuditFields(1); } var dealUnits = new DealUnit[] { new DealUnit { Deal = deals[0], Unit = units[0] } }; deals[0].DealUnits = dealUnits; context.Unit.AddRange(units); context.Deal.AddRange(deals); context.DealUnit.AddRange(dealUnits); context.SaveChanges(); }
public ActionResult Deals(string slug) { ViewBag.Title = slug.Humanize(LetterCasing.Title); using (var db = new DealContext()) { var deal = db.ActiveDeals.FirstOrDefault(x => x.DealSlug.Equals(slug)); var top = db.ActiveDeals.Where(x => x.CatSlug.Equals("dining")).Take(5).ToList(); if (deal == null) { return(RedirectToAction("NotFound")); } ViewBag.DealTitle = deal.Title; return(View(new DealModel() { Deal = deal, DealList = top })); } }
public ProductRepository(DealContext dbContext) { _dbContext = dbContext; }
public OrderRepository(DealContext dbContext) { _dbContext = dbContext; }
public UnitOfWork(string connectionString) { _dbContext = new DealContext(connectionString); }
/// <summary> /// Initializes a new instance of the <see cref="DealOperation"/> class. /// </summary> /// <param name="dealContent">The dealContent<see cref="object"/>.</param> /// <param name="directionType">The directionType<see cref="DirectionType"/>.</param> /// <param name="transfer">The transfer<see cref="DealTransfer"/>.</param> public DealOperation(object dealContent, DirectionType directionType, DealTransfer transfer) : this(dealContent) { direction = directionType; transferContext = transfer.Context; dealContext = transfer.MyHeader.Context; }
public DealRepository(DealContext dealContext) { this.dealContext = dealContext; }