//public HomeController(ILogger<HomeController> logger, MvcDbContext context)
        public HomeController(ILogger <HomeController> logger, MvcDbContext context)

        {
            _logger  = logger;
            _context = context;
            lh       = new LoginHelper();
        }
 public HomeController(ILogger <HomeController> logger, IWebHostEnvironment environment
                       , MvcDbContext _db)
 {
     hostingEnvironment = environment;
     _logger            = logger;
     db = _db;
 }
示例#3
0
        public ActionResult Registration(UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var password          = model.Password;
                var encryptedPassword = CustomEncrypt.Encrypt(password);

                using (var context = new MvcDbContext())
                {
                    var userAlreadyExists = context.Users.Any(usr => usr.Email == model.Email);
                    if (userAlreadyExists)
                    {
                        return(RedirectToAction("Registration"));
                    }
                    Users user = context.Users.Create();
                    user.Email    = model.Email;
                    user.Password = encryptedPassword;
                    user.Name     = model.Name;
                    user.Country  = model.Country;

                    context.Users.Add(user);
                    context.SaveChanges();
                }
                return(RedirectToAction("Login", "Auth"));
            }

            ModelState.AddModelError("", "One or more fields are invalid");
            return(View());
        }
示例#4
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcDbContext> >()))
            {
                if (context.User.Any())
                {
                    return;   // DB has been seeded
                }

                context.User.AddRange(
                    new User
                {
                    FirstName     = "James",
                    LastName      = "Hemingway",
                    Email         = "*****@*****.**",
                    Address       = "Hopsavej 2",
                    Telephone     = "10101010",
                    Zipcode       = "1010",
                    AddAutismInfo = true
                },

                    new User
                {
                    FirstName     = "Billy",
                    LastName      = "Brighton",
                    Email         = "*****@*****.**",
                    Address       = "Wassupgade 7",
                    Telephone     = "93057193",
                    Zipcode       = "4362",
                    AddAutismInfo = false
                },

                    new User
                {
                    FirstName     = "Mike",
                    LastName      = "Scallywag",
                    Email         = "*****@*****.**",
                    Address       = "Nejstræde 10",
                    Telephone     = "49571383",
                    Zipcode       = "8452",
                    AddAutismInfo = true
                },

                    new User
                {
                    FirstName     = "Hans",
                    LastName      = "Carlos Alexandros",
                    Email         = "*****@*****.**",
                    Address       = "Kanon Alle 5",
                    Telephone     = "10859291",
                    Zipcode       = "1846",
                    AddAutismInfo = true
                }
                    );
                context.SaveChanges();
            }
        }
示例#5
0
 public UserDataService(UserManager <ApplicationUser> userManager,
                        MvcDbContext dbContext,
                        RoleManager <IdentityRole> roleManager)
 {
     this.userManager = userManager;
     this.dbContext   = dbContext;
     this.roleManager = roleManager;
 }
示例#6
0
        public LectureDisplayModel(MvcDbContext context)
        {
            _context = context;

            //placeholder ops:
            NoOfTimeBlocks = 4;

            //TimeBlockDuration = TimeBlockDuration.Five;
        }
示例#7
0
        public ActionResult Create(Book book)
        {
            MvcDbContext db = new MvcDbContext();

            //db.Entry(book).State = System.Data.Entity.EntityState.Added;//状态跟踪
            db.Books.Add(book);
            db.SaveChanges();
            return(RedirectToAction(nameof(Index)));//nameof(Index) 当Index控制器重命名时跟着重命名
        }
示例#8
0
        // GET: Department
        public ActionResult Index()
        {
            MvcDbContext db = new MvcDbContext();

            List <Department> dptList = db.Departments.ToList();

            ViewBag.DepartmentList = new SelectList(dptList, "Id", "Dpt_Name");

            return(View());
        }
示例#9
0
 public AccountService(UserManager <ApplicationUser> userManager,
                       SignInManager <ApplicationUser> signInManager,
                       MvcDbContext dbContext,
                       RoleManager <IdentityRole> roleManager)
 {
     this.userManager   = userManager;
     this.signInManager = signInManager;
     this.dbContext     = dbContext;
     this.roleManager   = roleManager;
 }
        public ApiControllerIntegrationTests(CustomWebApplicationFactory <Startup> factory, ITestOutputHelper output)
        {
            this.output  = output;
            this.factory = factory;

            _client  = factory.CreateDefaultClient();
            _scope   = (factory.Services.GetRequiredService <IServiceScopeFactory>()).CreateScope();
            _context = _scope.ServiceProvider.GetRequiredService <MvcDbContext>();
            // database is now shared across tests
            _context.Database.EnsureCreated();
        }
示例#11
0
        public void PopulateTestData(MvcDbContext dbContext)
        {
            user = new User {
                username = "******", pw_hash = "somehash", pw_hash2 = "somehash", email = "seed@seed"
            };
            dbContext.user.Add(user);
            message = new Message {
                author_id = 0, author = user, text = "seed message"
            };
            dbContext.message.Add(message);

            dbContext.SaveChanges();
        }
示例#12
0
        public ActionResult Index(EmployeeVM model)
        {
            if (ModelState.IsValid == true)
            {
                // write your code may be you can save the data in database then return it
            }
            MvcDbContext      db      = new MvcDbContext();
            List <Department> dptList = db.Departments.ToList();

            ViewBag.DepartmentList = new SelectList(dptList, "Id", "Dpt_Name");

            return(View(model));
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcDbContext> >()))
            {
                if (context.Lecture.Any())
                {
                    return;   // DB has been seeded
                }

                context.Lecture.AddRange(
                    new Lecture
                {
                    Title       = "Autisme og mig",
                    StartTime   = DateTime.Parse("09:00"),
                    Speaker     = "Karl Bøje",
                    Description = "Min historie om autisme",
                    TimeFrame   = 2,
                },

                    new Lecture
                {
                    Title       = "Ro i sind",
                    StartTime   = DateTime.Parse("10:30"),
                    Speaker     = "Ove Larsen",
                    Description = "Metoder til at undgå stress",
                    TimeFrame   = 3,
                },

                    new Lecture
                {
                    Title       = "Stille barn",
                    StartTime   = DateTime.Parse("09:30"),
                    Speaker     = "Nadia Uldum",
                    Description = "Pædagogik i børnehaven",
                    TimeFrame   = 3,
                },

                    new Lecture
                {
                    Title       = "Autisme i samfundet",
                    StartTime   = DateTime.Parse("11:00"),
                    Speaker     = "Eva Marie Svendsen",
                    Description = "Viden i det danske samfund",
                    TimeFrame   = 2,
                }
                    );
                context.SaveChanges();
            }
        }
示例#14
0
        public ActionResult EmployeeDetail(int EmpId)
        {
            MvcDbContext db = new MvcDbContext();

            Employee oneEmployeeData = db.Employees.SingleOrDefault(x => x.Id == EmpId);

            EmployeeVM oneEmployeeViewModelData = new EmployeeVM();

            oneEmployeeViewModelData.Name           = oneEmployeeData.Name;
            oneEmployeeViewModelData.Address        = oneEmployeeData.Address;
            oneEmployeeViewModelData.DepartmentName = oneEmployeeData.Department.Dpt_Name;

            return(View(oneEmployeeViewModelData));
        }
示例#15
0
        public IActionResult Register(RegisterUserBindingModel model)
        {
            var user = new User
            {
                Username = model.Username,
                Password = model.Password
            };

            using (var context = new MvcDbContext())
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
            return(View());
        }
示例#16
0
        public ActionResult Delete(int id)
        {
            using (var dbContext = new MvcDbContext())
            {
                var model = dbContext.Lists.Find(id);
                if (model == null)
                {
                    return(HttpNotFound());
                }

                dbContext.Lists.Remove(model);
                dbContext.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
示例#17
0
        // GET: Hyperlinks_Ancor_Tag
        public ActionResult Index()
        {
            MvcDbContext    db           = new MvcDbContext();
            List <Employee> employeeList = db.Employees.ToList();

            List <EmployeeVM> employeeVmList = employeeList.Select(x => new EmployeeVM
            {
                Name = x.Name,
                Id   = x.Id
            }).ToList();



            return(View(employeeVmList));
        }
示例#18
0
        public ActionResult Edit(int id)
        {
            ListViewModel model = new ListViewModel();

            using (var dbContext = new MvcDbContext())
            {
                var listItem = dbContext.Lists.Find(id);
                model.Details     = listItem.Details;
                model.Id          = listItem.Id;
                model.Public      = listItem.Public == "YES";
                model.Date_Posted = listItem.Date_Posted;
                model.Time_Posted = listItem.Time_Posted;
                model.Date_Edited = listItem.Date_Edited;
                model.Time_Edited = listItem.Time_Edited;
            }
            return(View(model));
        }
示例#19
0
        public IActionResult <UserPrifileViewModel> Profile(AddNoteBindingModel model)
        {
            using (var context = new MvcDbContext())
            {
                var user = context.Users.FirstOrDefault(x => x.iD == model.Id);

                var note = new Note
                {
                    Title   = model.Title,
                    Content = model.Content
                };
                user.Notes.Add(note);
                context.SaveChanges();

                return(Profile(model.Id));
            }
        }
示例#20
0
        public ActionResult Index(ListViewModel model)
        {
            if (ModelState.IsValid)
            {
                string timeToday = DateTime.Now.ToString("h:mm:ss tt");
                string dateToday = DateTime.Now.ToString("M/dd/yyyy");

                Claim  sessionEmail = ClaimsPrincipal.Current.FindFirst(ClaimTypes.Email);
                string userEmail    = sessionEmail.Value;
                string text_details = Request.Form["text_details"];
                string check_public = Request.Form["check_public"];
                using (var dbContext = new MvcDbContext())
                {
                    Users user = dbContext.Users.FirstOrDefault(usr => usr.Email == userEmail);
                    Lists list = dbContext.Lists.Create();
                    list.Details     = text_details;
                    list.Date_Posted = dateToday;
                    list.Time_Posted = timeToday;
                    if (user != null)
                    {
                        list.User_Id = user.Id;
                        if (check_public != null)
                        {
                            list.Public = "YES";
                        }
                        else
                        {
                            list.Public = "NO";
                        }
                        dbContext.Lists.Add(list);
                        dbContext.SaveChanges();
                        ModelState.Clear();
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "One or more fields are having an incorrect format");
            }

            List <ListViewModel> listItems = GetListItems();

            return(View(listItems));
        }
示例#21
0
        // GET: ShowMultipleTableData
        public ActionResult Index()
        {
            MvcDbContext    db           = new MvcDbContext();
            List <Employee> employeeList = db.Employees.ToList(); // take the list of employee from database

            // EmployeeVM employeeVm = new EmployeeVM(); // my customized data model that means view model


            List <EmployeeVM> employeeVmList = employeeList.Select(x => new EmployeeVM
            {
                Id             = x.Id,
                Name           = x.Name,
                Address        = x.Address,
                DepartmentId   = x.DepartmentId,
                DepartmentName = x.Department.Dpt_Name
            }).ToList();

            return(View(employeeVmList));
        }
示例#22
0
        private static List <ListViewModel> GetListItems()
        {
            List <ListViewModel> list = new List <ListViewModel>();

            using (var dbContext = new MvcDbContext())
            {
                list = dbContext.Lists.Select(item => new ListViewModel
                {
                    Id          = item.Id,
                    Details     = item.Details,
                    Date_Edited = item.Date_Edited,
                    Time_Edited = item.Time_Edited,
                    Date_Posted = item.Date_Posted,
                    Time_Posted = item.Time_Posted,
                    Public      = item.Public == "YES"
                }).ToList();
            }
            return(list);
        }
示例#23
0
        // GET: Test
        public ActionResult Index()
        {
            MvcDbContext db = new MvcDbContext();

            Employee employee = db.Employees.SingleOrDefault(x => x.Id == 1);



            EmployeeVM employeeVm = new EmployeeVM();

            employeeVm.Id           = employee.Id;
            employeeVm.Name         = employee.Name;
            employeeVm.DepartmentId = employee.DepartmentId;
            employeeVm.Address      = employee.Address;



            return(View(employeeVm));
        }
示例#24
0
        public IActionResult <AllNeededUserDataViewModel> All()
        {
            List <UserBindingModel> users = null;

            using (var context = new MvcDbContext())
            {
                users = context.Users.Select(x => new UserBindingModel
                {
                    Username = x.Username,
                    Id       = x.iD
                }).ToList();
            }

            var viewModel = new AllNeededUserDataViewModel()
            {
                Users = users
            };

            return(View(viewModel));
        }
示例#25
0
        public IActionResult <UserPrifileViewModel> Profile(int id)
        {
            using (var context = new MvcDbContext())
            {
                var user = context.Users.FirstOrDefault(x => x.iD == id);

                var viewModel = new UserPrifileViewModel
                {
                    Id       = user.iD,
                    Username = user.Username,
                    Notes    = user.Notes.Select(x => new NoteViewModel
                    {
                        Title   = x.Title,
                        Content = x.Content
                    })
                };

                return(View(viewModel));
            }
        }
示例#26
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcDbContext(
                       serviceProvider.GetRequiredService <DbContextOptions <MvcDbContext> >()))
            {
                // Look for any messages.
                if (context.message.Any())
                {
                    Console.WriteLine("the db is not empty!");    // DB has been seeded

                    return;
                }
                else
                {
                    Console.WriteLine("db it not found/or empty");
                    return;
                }

                //add something to db?
            }
        }
示例#27
0
        public ActionResult Login(UserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                //handle the error message: return to the login page
                return(View(model));
            }

            using (var context = new MvcDbContext())
            {
                //fetch the user details from db and validate user
                string email    = model.Email;
                string password = model.Password;

                Users user = context.Users.FirstOrDefault(usr => usr.Email == email);
                if (user != null)
                {
                    var encryptedPassword = user.Password;
                    var decryptedPassword = CustomDecrypt.Decrypt(encryptedPassword);
                    if (password == decryptedPassword)
                    {
                        List <Claim> claims = new List <Claim> {
                            new Claim(ClaimTypes.Name, user.Name),
                            new Claim(ClaimTypes.Email, user.Email),
                            new Claim(ClaimTypes.Country, user.Country)
                        };

                        ClaimsIdentity identity = new ClaimsIdentity(claims, "ApplicationCookie");

                        IOwinContext           owinContext = Request.GetOwinContext();
                        IAuthenticationManager authManager = owinContext.Authentication;
                        authManager.SignIn(identity);

                        string redirectUrl = GetRedirectUrl(model.ReturnUrl);
                        return(Redirect(redirectUrl));
                    }
                }
            }
            return(View(model));
        }
示例#28
0
 public ActionResult Registration(UserViewModel uservm)
 {
     if (ModelState.IsValid)
     {
         var encryptedPassword = CustomEncrypt.Encrypt(uservm.Password);
         using (var context = new MvcDbContext())
         {
             var user = context.Users.Create();
             user.Email    = uservm.Email;
             user.Password = encryptedPassword;
             user.Country  = uservm.Country;
             user.Name     = uservm.Name;
             context.Users.Add(user);
             context.SaveChanges();
         }
     }
     else
     {
         ModelState.AddModelError("", "One or more fields are invalid");
     }
     return(View());
 }
示例#29
0
        public ActionResult Login(UserViewModel model)
        {
            if (!ModelState.IsValid) //checks if input fields have the correct format and are valid
            {
                //if not, then return the same login view, with the inputs as is, so user doesn't have to retype them
                return(View(model));
            }

            using (var context = new MvcDbContext())
            {
                var user = model.Email != null?context.Users.FirstOrDefault(u => u.Email == model.Email) : null;

                if (user != null)
                {
                    var email             = user.Email;
                    var password          = user.Password;
                    var decryptedPassword = CustomDecrypt.Decrypt(password);
                    if (model.Email == email && model.Password == decryptedPassword)
                    {
                        //create a list of claims
                        List <Claim> claims = new List <Claim> {
                            new Claim(ClaimTypes.Name, user.Name),
                            new Claim(ClaimTypes.Email, user.Email),
                            new Claim(ClaimTypes.Country, user.Country)
                        };
                        //create a claims identity based on above claims, and instruct it to use cookie
                        var identity = new ClaimsIdentity(claims, "ApplicationCookie");

                        var owinContext = Request.GetOwinContext();
                        var authManager = owinContext.Authentication; //gets the authentication middleware functionality available on the current context
                        authManager.SignIn(identity);

                        string redirectUrl = GetRedirectUrl(model.ReturnUrl);
                        return(Redirect(redirectUrl));
                    }
                }
            }
            return(View(model)); //if email/psw entered by user is not correct, show the loginpage again
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcDbContext> >()))
            {
                if (context.Room.Any())
                {
                    return;   // DB has been seeded
                }

                context.Room.AddRange(
                    new Room
                {
                    Name     = "A2.10",
                    Capacity = 20
                },

                    new Room
                {
                    Name     = "C1.07",
                    Capacity = 5
                },

                    new Room
                {
                    Name     = "B3.04",
                    Capacity = 25
                },

                    new Room
                {
                    Name     = "A1.05",
                    Capacity = 10
                }
                    );
                context.SaveChanges();
            }
        }