Пример #1
0
        public void SaveOrUpdate(string startupUrl, string roleStartupType, long[] roles)
        {
            using (var txn = _entityRepository.BeginTransaction())
            {
                foreach (var item in roles)
                {
                    var startup         = new NccStartup();
                    var startupType     = (StartupType)Enum.Parse(typeof(StartupType), roleStartupType);
                    var existingStartup = Get(item, StartupFor.Role);
                    var permission      = _nccPermissionRepository.Get(item);

                    if (existingStartup == null)
                    {
                        startup.Permission  = permission;
                        startup.StartupFor  = StartupFor.Role;
                        startup.StartupType = startupType;
                        startup.StartupUrl  = startupUrl;
                        _entityRepository.Add(startup);
                    }
                    else
                    {
                        existingStartup.Permission  = permission;
                        existingStartup.StartupFor  = StartupFor.Role;
                        existingStartup.StartupType = startupType;
                        existingStartup.StartupUrl  = startupUrl;
                        _entityRepository.Edit(existingStartup);
                    }
                }
                _entityRepository.SaveChange();
                txn.Commit();
            }
        }
Пример #2
0
        public NccStartup Update(NccStartup entity)
        {
            var oldEntity = _entityRepository.Get(entity.Id);

            if (oldEntity != null)
            {
                using (var txn = _entityRepository.BeginTransaction())
                {
                    CopyNewData(oldEntity, entity);
                    _entityRepository.Edit(oldEntity);
                    _entityRepository.SaveChange();
                    txn.Commit();
                }
            }

            return(entity);
        }