Exemple #1
0
 public ActionResult RegisterGuard([Bind(Include = "PersonalCode,Name,Surname,DormitoryId,Username,Password")] Guard guard)
 {
     if (IsLoggedOn())
     {
         ViewBag.DormitoryId     = new SelectList(dormitoryRepository.GetAll(), "ID", "Name", guard.DormitoryId);
         ViewBag.DefaultPassword = guard.Password;
         guard.Password          = DataContract.Configuration.Encryption(guard.Password);
         if (guardRepository.Create(guard).ReasonPhrase == "Created")
         {
             return(RedirectToAction("Successful"));
         }
     }
     return(RedirectToAction("LoginForm", "Main"));
 }
        public void IsCreatable()
        {
            Random random    = new Random(DateTime.Now.Millisecond);
            Guard  testGuard = new Guard
            {
                DormitoryId  = 2,
                Name         = Generation.GetRandomAlphaNumeric(),
                Password     = Generation.GetRandomAlphaNumeric(),
                PersonalCode = random.Next(),
                Surname      = Generation.GetRandomAlphaNumeric(),
                Username     = Generation.GetRandomAlphaNumeric()
            };
            HttpResponseMessage response = repository.Create(testGuard);
            string    jsonContents       = response.Content.ReadAsStringAsync().Result;
            Dormitory createdGuard       = JsonConvert.DeserializeObject <Dormitory>(jsonContents);

            Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.Created, "Guard creation test has failed.");
            Assert.Equals(testGuard, createdGuard);
        }