public async Task <NormalizeAd> FindAdByNameAndIdAndManagerAccount(string name, string accountname, int managetAccountId) { using (var db = new AdsDb()) { return(await FirstOrDefault(f => f.Name == name && f.AccountNumber == accountname && f.ManagerAccountId == managetAccountId)); } }
public IActionResult DeleteAd(int id) { AdsDb db = new AdsDb(_connectionString); db.DeleteAd(id); return(Redirect("/Home/Index")); }
public IActionResult SignUp(User user, string password) { var db = new AdsDb(_connectionString); db.AddUser(user, password); return(Redirect("/account/login")); }
public IActionResult MyAccount() { var db = new AdsDb(_connectionString); var vm = new AdsViewModel(); User CurrentUser = db.GetByEmail(User.Identity.Name); vm.Ads = db.GetAds().Where(a => a.UserId == CurrentUser.Id).ToList(); return(View(vm)); }
public async Task UpdateAdMetric(NormalizeAd ad) { using (var db = new AdsDb()) { await db.Ads.Where(w => w.Name == ad.Name) .Set(s => s.MetricView, ad.MetricView) .Set(s => s.MetricBudget, ad.MetricBudget) .UpdateAsync(); } }
public IActionResult NewAd(Ad ad) { AdsDb db = new AdsDb(_connectionString); ad.Date = DateTime.Now; User CurrentUser = db.GetByEmail(User.Identity.Name); ad.UserId = CurrentUser.Id; db.AddAd(ad); return(Redirect("/Home/index")); }
public override async Task Create(NormalizeAd ad) { using (var db = new AdsDb()) { var adDb = await FindAdByNameAndIdAndManagerAccount(ad.Name, ad.AccountNumber, ad.ManagerAccountId); if (adDb != null) { await Update(ad); return; } await db.InsertAsync(ad); } }
public IActionResult Index() { var db = new AdsDb(_connectionString); var vm = new AdsViewModel(); vm.Ads = db.GetAds(); vm.IsAuthenticated = User.Identity.IsAuthenticated; if (User.Identity.IsAuthenticated) { var email = User.Identity.Name; vm.CurrentUser = db.GetByEmail(email); } return(View(vm)); }
public IActionResult Login(string email, string password) { var db = new AdsDb(_connectionString); var user = db.Login(email, password); if (user == null) { TempData["message"] = "Invalid email/password - please try again."; return(Redirect("/account/login")); } var claims = new List <Claim> { new Claim("user", email) }; HttpContext.SignInAsync(new ClaimsPrincipal( new ClaimsIdentity(claims, "Cookies", "user", "role"))).Wait(); return(Redirect("/home/newad")); }