示例#1
0
        public void TestAdministratorGetAllOK2()
        {
            IMMRequestContext       IMMRequestContext = ContextFactory.GetNewContext();
            AdministratorRepository adminRepo         = new AdministratorRepository(IMMRequestContext);

            adminRepo.Add(new Administrator
            {
                Id       = Guid.NewGuid(),
                Name     = "Just Testing",
                Email    = "*****@*****.**",
                Password = "******"
            });

            adminRepo.Add(new Administrator
            {
                Id       = Guid.NewGuid(),
                Name     = "Just Testing again",
                Email    = "*****@*****.**",
                Password = "******"
            });

            adminRepo.Save();

            var admins = adminRepo.GetAll().ToList().Count();

            Assert.AreEqual(2, admins);
        }
示例#2
0
        public void TestAdministratorGet2()
        {
            var id = Guid.NewGuid();
            IMMRequestContext       IMMRequestContext = ContextFactory.GetNewContext();
            AdministratorRepository adminRepo         = new AdministratorRepository(IMMRequestContext);

            Administrator admin1 = new Administrator()
            {
                Id       = Guid.NewGuid(),
                Name     = "Just Testing",
                Email    = "*****@*****.**",
                Password = "******"
            };

            Administrator admin2 = new Administrator()
            {
                Id       = id,
                Name     = "Just Testing again",
                Email    = "*****@*****.**",
                Password = "******"
            };

            adminRepo.Add(admin1);
            adminRepo.Add(admin2);
            adminRepo.Save();

            Assert.AreEqual(adminRepo.Get(id), admin2);
        }
示例#3
0
        public ActionResult Edit(int id, AdminControllerAdminVM model)
        {
            AdministratorRepository adminRepository = new AdministratorRepository();

            TryUpdateModel(model);
            if (ModelState.IsValid)
            {
                Administrator admin = null;
                if (adminRepository.GetAll(filter: a => a.UserName == model.UserName).FirstOrDefault() == null)
                {
                    admin           = new Administrator();
                    admin.UserName  = model.UserName;
                    admin.Password  = SecurityService.CreateHash(model.Password);
                    admin.FirstName = model.FirstName;
                    admin.LastName  = model.LastName;
                    admin.IsActive  = true;
                    adminRepository.Save(admin);
                    return(RedirectToAction("ManageAdministrators"));
                }
                else
                {
                    throw new ArgumentException("Invalid username !");
                }
            }
            return(View(model));
        }
示例#4
0
        public void TestAdministratorGetAll3()
        {
            IMMRequestContext       IMMRequestContext = ContextFactory.GetNewContext();
            AdministratorRepository adminRepo         = new AdministratorRepository(IMMRequestContext);

            Administrator admin = new Administrator()
            {
                Id       = Guid.NewGuid(),
                Name     = "Just Testing",
                Email    = "*****@*****.**",
                Password = "******"
            };

            adminRepo.Add(admin);
            adminRepo.Save();

            var admins = adminRepo.GetAll().ToList();

            Assert.AreEqual(admins.First(), admin);
        }
 public ActionResult Edit(int id, AdminControllerAdminVM model)
 {
     AdministratorRepository adminRepository = new AdministratorRepository();
     TryUpdateModel(model);
     if (ModelState.IsValid)
     {
         Administrator admin = null;
         if (adminRepository.GetAll(filter: a => a.UserName == model.UserName).FirstOrDefault() == null)
         {
             admin = new Administrator();
             admin.UserName = model.UserName;
             admin.Password = SecurityService.CreateHash(model.Password);
             admin.FirstName = model.FirstName;
             admin.LastName = model.LastName;
             admin.IsActive = true;
             adminRepository.Save(admin);
             return RedirectToAction("ManageAdministrators");
         }
         else
         {
             throw new ArgumentException("Invalid username !");
         }
     }
     return View(model);
 }