public async Task <IActionResult> Edit(int id, [Bind("UserId,UserName,UserPassword,UserImagePath,Address,PostCode,Phone,BirthDate,IsOnline,NoOfAccess,CreationDate,NoOfBlock")] WebUsers webUsers) { if (id != webUsers.UserId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(webUsers); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WebUsersExists(webUsers.UserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(webUsers)); }
public IActionResult Profile() { //test WebUsers user = webUsers.Find(p => p.UserId == 1); List <UserFavorites> prods = (from favs in user.UserFavorites where favs.UserId == user.UserId select favs).ToList(); List <Products> mylist = new List <Products>(); foreach (var item in prods) { mylist.Add(xproducts.Find(p => p.ProductId == item.ProductId)); } ViewBag.fav = mylist; //database //WebUsers user = _users.getWebUser(1); //List<UserFavorites> prods = (from favs in user.UserFavorites // where favs.UserId == user.UserId // select favs).ToList(); //List<Products> mylist = new List<Products>(); //foreach (var item in prods) //{ // mylist.Add(_products.getProductByID(item.ProductId)); //} //ViewBag.fav = mylist; return(View(user)); }
public WebUsers getWebUser(int id) { WebUsers webuser = (from user in _Context.WebUsers where user.UserId == id select user).FirstOrDefault(); return(webuser); }
public async Task <IActionResult> Create([Bind("UserId,UserName,UserPassword,UserImagePath,Address,PostCode,Phone,BirthDate,IsOnline,NoOfAccess,CreationDate,NoOfBlock")] WebUsers webUsers) { if (ModelState.IsValid) { _context.Add(webUsers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(webUsers)); }
public IActionResult addToFavorites(int productid, int userid = 1) { //test WebUsers xuser = webUsers.Find(p => p.UserId == userid); xuser.UserFavorites.Add(new UserFavorites() { UserId = xuser.UserId, ProductId = productid }); //database //_products.addToFavorites(productid,1); return(View(nameof(Offers))); }
public IActionResult Authenticate([FromBody] WebUsers userParam) { try { if (userParam == null) { return(BadRequest(new { message = "Bad Request Data" })); } var user = _userService.Authenticate(userParam.Username, userParam.Password); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(user)); } catch { return(BadRequest()); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, WebUsers webuser) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859 try { using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>() .CreateScope()) { serviceScope.ServiceProvider.GetService <ApplicationDbContext>() .Database.Migrate(); } } catch { } } app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseStaticFiles(); app.UseIdentity(); // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); using (var serviceScope = app.ApplicationServices .GetRequiredService <IServiceScopeFactory>() .CreateScope()) { var context = serviceScope.ServiceProvider.GetService <OptionsContext>(); SeedData.Initialize(context); var test = serviceScope.ServiceProvider.GetService <ApplicationDbContext>(); await webuser.InitializeDataAsync(); //trying to seed users // var usercontext = serviceScope.ServiceProvider.GetService<ApplicationDbContext>(); // SeedUsers.Initialize(usercontext); } }