public ActionResult Index(int profileID) { if (profileID == 0) return new HttpNotFoundResult(); using (var uow = ObjectFactory.GetInstance<IUnitOfWork>()) { var profileDO = uow.ProfileRepository.GetQuery().FirstOrDefault(pn => pn.Id == profileID); var vm = new ProfileVM(profileDO); return View(vm); } }
public ActionResult UpdateProfile(ProfileVM value) { using (var uow = ObjectFactory.GetInstance<IUnitOfWork>()) { var currentIDs = value.Nodes.SelectMany(GetCurrentIDs).Where(id => id > 0).ToList(); var rowsToDelete = uow.ProfileNodeRepository.GetQuery().Where(pn => !currentIDs.Contains(pn.Id)).ToList(); foreach (var rowToDelete in rowsToDelete) { foreach(var profileItem in rowToDelete.ProfileItems.ToList()) uow.ProfileItemRepository.Remove(profileItem); uow.ProfileNodeRepository.Remove(rowToDelete); } CreateNewNodes(uow, value.Id, null, value.Nodes); uow.SaveChanges(); } return Json(true); }
private IEnumerable<int> GetCurrentIDs(ProfileVM.ProfileNodeVM profileNode) { yield return profileNode.Id; if (profileNode.Children != null) foreach (var child in profileNode.Children) foreach (var id in GetCurrentIDs(child)) yield return id; }