Пример #1
0
 public void Edit(Person p)
 {
     if ( p != null && p.ID != null ) {
         db.Entry(p).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #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")) };
        }
Пример #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();
         }
     }
 }
Пример #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);
        }
Пример #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));
        }
Пример #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);
 }
Пример #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;
        }
Пример #8
0
 public Person Retrieve(Person p)
 {
     Person person = db.Person.Find(p);
     return person;
 }
Пример #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;
        }
Пример #10
0
        public ActionResult PersonSearchPartial(Person p)
        {
            //PersonService personCtrl = new PersonService();
            //List<Person> ls = personCtrl.RetrievePersons();

            return PartialView("_PersonSearchPartial");
        }