Esempio n. 1
0
 public void Edit(Person p)
 {
     if ( p != null && p.ID != null ) {
         db.Entry(p).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 2
0
        public Person Create(Person p)
        {
            db.Person.Add(p);
            db.SaveChanges();
            string str = ValidatePersonProperty(p);
            if ( str.Length > 0 ) { throw new Exception(str); }

            return db.Person.FirstOrDefault(x => x.Name == p.Name && x.LastName == p.LastName && x.DateBird == p.DateBird && x.Email == p.Email);
            //return new Person { ID = 1, Name = "Daniela", DateBird = DateTime.Parse(string.Format("{0:MM/dd/yyyy}", "03/31/1985")) };
        }
Esempio n. 3
0
 public void Delete(Person p)
 {
     if ( p != null ) {
         Person person = null;
         person = db.Person.FirstOrDefault(x => x.ID == p.ID);
         if ( person != null ) {
             db.Person.Remove(person);
             db.SaveChanges();
         }
     }
 }
Esempio n. 4
0
        public ActionResult Create(Person person)
        {

            if (ModelState.IsValid)
            {
                _personCtrl = new PersonService();
                _personCtrl.Create(person);
                //personCtrl.Create(person);
                //db.Person.Add(person);
                //db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View("Create",person);
        }
Esempio n. 5
0
        public void TestMethodPersonControllerInsertMoq()
        {
            string expected = "Details";
            var moq = new Mock<IPersonService>();
            PersonController controller = new PersonController(moq.Object);

            //act
            long id = 2;
            //Person p = new Person { Name = "Daniela A", DateBird = DateTime.Now.AddYears(-20), LastName = "Avila", Email = "*****@*****.**", ImgDir = "~/Content/Img" };
            Person p = new Person();

            RedirectToRouteResult result = controller.Create(p) as RedirectToRouteResult;

            //assert
            moq.Verify(a => a.Create(p));
        }
Esempio n. 6
0
 public ActionResult Edit(Person person)
 {
     if (ModelState.IsValid)
     {
         _personCtrl.Edit(person);
         //db.Entry(person).State = EntityState.Modified;
         //db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View("Edit",person);
 }
Esempio n. 7
0
        private string ValidatePerson(Person p)
        {
            DbEntityValidationResult results;
            string sError = string.Empty;
            using ( ComunContext context = new ComunContext() ) {
                results = context.Entry(p).GetValidationResult();
            }

            foreach ( var error in results.ValidationErrors ) {
                sError += error.PropertyName + " : " + error.ErrorMessage;
            }

            return sError;
        }
Esempio n. 8
0
 public Person Retrieve(Person p)
 {
     Person person = db.Person.Find(p);
     return person;
 }
Esempio n. 9
0
        private string ValidatePersonProperty(Person p)
        {
            ICollection<DbValidationError> results;
            string sError = string.Empty;
            using ( var context = new ComunContext() ) {
                results = context.Entry(p).Property(a => a.Name).GetValidationErrors();
            }
            foreach ( DbValidationError item in results ) {
                sError += item.PropertyName + " : " + item.ErrorMessage;
            }

            return sError;
        }
Esempio n. 10
0
        public ActionResult PersonSearchPartial(Person p)
        {
            //PersonService personCtrl = new PersonService();
            //List<Person> ls = personCtrl.RetrievePersons();

            return PartialView("_PersonSearchPartial");
        }