public void Edit(Person p) { if ( p != null && p.ID != null ) { db.Entry(p).State = EntityState.Modified; db.SaveChanges(); } }
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")) }; }
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(); } } }
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); }
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)); }
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); }
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; }
public Person Retrieve(Person p) { Person person = db.Person.Find(p); return person; }
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; }
public ActionResult PersonSearchPartial(Person p) { //PersonService personCtrl = new PersonService(); //List<Person> ls = personCtrl.RetrievePersons(); return PartialView("_PersonSearchPartial"); }