Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 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;
 }