public void Update(Models.Contact contact) { Contact contactEntity = new Contact { Id = contact.Id, Name = contact.Name, Address = contact.Address, Phone = contact.Phone }; var mergedContactEntity = session.Merge(contactEntity); session.Update(mergedContactEntity); }
private bool GetLatestStateFromConfigurationManagement(object entity, object[] state, string[] propertyNames) { bool?appFrontend = false; Type classType; Domain.Application application; classType = NHibernate.Proxy.NHibernateProxyHelper.GetClassWithoutInitializingProxy(entity); if (typeof(IVersionControlled).IsAssignableFrom(classType)) { if (((bool)state[propertyNames.ToList().IndexOf("IsLocked")]) && ((string)state[propertyNames.ToList().IndexOf("LockedBy")]) != Environment.UserName) { IVersionControlled dbobject = (IVersionControlled)GetObjectFromState(classType, state, propertyNames); dbobject.Id = ((IVersionControlled)entity).Id; application = GetApplicationForDomainObject(dbobject); appFrontend = application.IsFrontend.Value; if (appFrontend == null) { return(false); } Spring.Context.IApplicationContext ctx = Spring.Context.Support.ContextRegistry.GetContext(); NHibernate.ISessionFactory sessionFactory = ((NHibernate.ISessionFactory)ctx["SessionFactory"]); NHibernate.ISession session = Spring.Data.NHibernate.SessionFactoryUtils.GetSession(sessionFactory, false); System.Configuration.AppSettingsReader appReader = new System.Configuration.AppSettingsReader(); string rootPath = appReader.GetValue("RepositoryPath", typeof(System.String)).ToString(); string parentPath = System.IO.Path.Combine(rootPath, application.Name + (appFrontend.Value ? "_Frontend" : "_Backend")); string filePath = System.IO.Path.Combine(parentPath, classType.Name); string fileName = ((IVersionControlled)dbobject).RepositoryFileName + ".xml"; string fullPath = System.IO.Path.Combine(filePath, fileName); System.IO.FileInfo fi = new System.IO.FileInfo(fullPath); if (fi.Exists) { System.Xml.Serialization.XmlSerializer xmlSerie = new System.Xml.Serialization.XmlSerializer(classType); System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new System.IO.StringReader(fi.OpenText().ReadToEnd())); DataAccess.DomainXmlSerializationHelper.VisualComponentRefObjects.Clear(); object domainObject = xmlSerie.Deserialize(reader); foreach (IDomainObject obj in DataAccess.DomainXmlSerializationHelper.VisualComponentRefObjects) { session.Merge(obj); } ((IVersionControlled)domainObject).IsLocked = true; ((IVersionControlled)domainObject).LockedBy = dbobject.LockedBy; ((IVersionControlled)domainObject).LockedDate = dbobject.LockedDate; ((IDomainObject)domainObject).IsTransient = false; SetStateFromObject(domainObject, classType, state, propertyNames); return(true); } } } return(true); }