예제 #1
0
 private void SaveContacts(Contact m2)
 {
     var session = NHibernateContext.SesionFactory;
     using (var transaction = session.BeginTransaction())
     {
         session.Merge(m2);
         transaction.Commit();
     }
 }
예제 #2
0
 public void ShouldIncludeAddedContacts()
 {
     createUsr("Jill");
     var user = userMgr.GetUserByName("Jill");
     var newContact = new Contact("Johnny", "USA");
     user.ContactsList.Add(newContact);
     userMgr.UpdateUser(user);
     ListUsers().Any(p => p.Id == newContact.Id).Should().BeTrue();
 }
예제 #3
0
 //
 // GET: /Contact/Delete/5
 public ActionResult Delete(int id)
 {
     aCookie = Request.Cookies["loginCookie"];
     if (aCookie != null)
     {
         conatact = userRepo.GetUserContactById(id);
         return View(conatact);
     }
     return RedirectToAction("Index", "Home");
 }
예제 #4
0
        public void UpdateContact(int id, Contact m1)
        {
            var session = NHibernateContext.SesionFactory;
            using (var transaction = session.BeginTransaction())
            {
                m1.Id = id;
                session.Merge(m1);

                transaction.Commit();
            }
        }
예제 #5
0
        public void ShouldRemoveDeletedContacts()
        {
            createUsr("Jill");
            var user = userMgr.GetUserByName("Jill");
            var contactToBeDeleted = new Contact("Michelle", "Germany");
            user.ContactsList.Add(contactToBeDeleted);

            user.ContactsList.Remove(contactToBeDeleted);
            userMgr.UpdateUser(user);

            ListUsers().Any(p => p.Id == contactToBeDeleted.Id).Should().BeFalse();
        }
예제 #6
0
        public void SaveAllFields()
        {
            createUsr("Jill");
            var user = userMgr.GetUserByName("Jill");
            var newContact = new Contact("Mike", "UK");
            user.ContactsList.Add(newContact);
            userMgr.UpdateUser(user);

            Contact createdUser = userMgr.GetUserContactById(newContact.Id);
            createdUser.Name.Should().Be(newContact.Name);
            createdUser.Address.Should().Be(newContact.Address);
        }
예제 #7
0
        public Contact GetContactById(int id)
        {
            var Contact = new Contact("testName", "testAddress");

            var session = NHibernateContext.SesionFactory;
            using (var transaction = session.BeginTransaction())
            {
                Contact = session.Get<Contact>(id);
                transaction.Commit();
            }
            return Contact;
        }
예제 #8
0
        public ActionResult Create(Contact newContact)
        {
            aCookie = Request.Cookies["loginCookie"];
            if (aCookie != null)
            {

                if (ModelState.IsValid)
                {
                    UserName = Server.HtmlEncode(aCookie.Value);
                    user = userRepo.GetUserByName(UserName);

                    user.ContactsList.Add(newContact);
                    userRepo.UpdateUser(user);
                    return RedirectToAction("Index");
                }
                return View(newContact);
            }
            return RedirectToAction("Index", "Home");
        }
예제 #9
0
        public ActionResult Delete(int id, Contact newContact)
        {
            aCookie = Request.Cookies["loginCookie"];
            if (aCookie != null)
            {
                UserName = Server.HtmlEncode(aCookie.Value);
                user = userRepo.GetUserByName(UserName);
                var contactList = user.ContactsList;
                contactList.Remove(contactList.SingleOrDefault(x => x.Id == newContact.Id));

                userRepo.UpdateUser(user);
                return RedirectToAction("Index");
            }
            return RedirectToAction("Index", "Home");
        }
예제 #10
0
 public ActionResult Edit(int id, Contact newContact)
 {
     aCookie = Request.Cookies["loginCookie"];
     if (aCookie != null)
     {
         if (ModelState.IsValid)
         {
             UserName = Server.HtmlEncode(aCookie.Value);
             user = userRepo.GetUserByName(UserName);
             newContact.User = user;
             var cr = new ContactRepo();
             cr.UpdateContact(id,newContact);
             return RedirectToAction("Index");
         }
         else
         {
             return View(userRepo.GetUserContactById(id));
         }
     }
     return RedirectToAction("Index", "Home");
 }
예제 #11
0
        public void UpdateAllFields()
        {
            createUsr("Jill");
            var user = userMgr.GetUserByName("Jill");
            var oldContact = new Contact("Wills", "Australia");
            user.ContactsList.Add(oldContact);

            var newContact = new Contact("Alice", "Denmark");

            var contactList = user.ContactsList;
            contactList.Remove(contactList.SingleOrDefault(x => x.Id == oldContact.Id));
            user.ContactsList.Add(newContact);
            userMgr.UpdateUser(user);

            var newUser = userMgr.GetUserByName("Jill");
            Contact updatedContact = userMgr.GetUserContactById(newContact.Id);

            updatedContact.Name.Should().Be(newContact.Name);
            updatedContact.Address.Should().Be(newContact.Address);
        }
예제 #12
0
 public void AddContact(Contact m1)
 {
     SaveContacts(m1);
 }