public void Save(PersonRelation obj)
 {
     if (obj.Id == 0)
         context.Entry(obj).State = System.Data.Entity.EntityState.Added;
     else
         context.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }
Esempio n. 2
0
 public ActionResult AddRelatedPerson(PersonRelation obj)
 {
     if(ModelState.IsValid)
     {
         if (obj.Relationship1Id.HasValue && obj.Relationship2Id.HasValue)
         {
             dataManager.PersonRelations.Save(obj);
             return RedirectToAction("Show", new { Id = obj.Person1Id });
         }
         if (!obj.Relationship1Id.HasValue) ModelState.AddModelError("Relationship1Id", "Укажите тип взаимоотношения.");
         if (!obj.Relationship2Id.HasValue) ModelState.AddModelError("Relationship2Id", "Укажите тип взаимоотношения.");
     }
     var relationships = new List<SelectListItem> { new SelectListItem() };
     relationships.AddRange(from n in dataManager.Relationships.GetAll()
                            select new SelectListItem
                            {
                                Text = n.Type,
                                Value = n.Id.ToString()
                            });
     ViewBag.Relationships = relationships;
     return View(obj);
 }