/// <Update> /// Update/Change value of blog post /// </summary> /// <param name="blog_Posts">Set Values in a blog posts Class Property and Pass the same Object of blog posts Class in paremeter.(Domain.Blog_Posts)</param> /// <returns></returns> public int Update(Blog_Posts blog_Posts) { int update = 0; try { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action, to update Data session.Update(blog_Posts.Id, blog_Posts); transaction.Commit(); update = 1; } //End Trsaction } //End session } catch (Exception ex) { Console.WriteLine("Error : " + ex.StackTrace); } return(update); }
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); }
internal static void Disable(this NHibernate.ISession session, IActiveDataItem item) { if (session == null) { throw new ArgumentNullException("session"); } if (item == null) { throw new ArgumentNullException("item"); } string tableName = item.TableName(); if (!_allowed.Contains(tableName)) { throw new ArgumentException("TableName is invalid.", "tableName"); } int record = item.Record(); if (record == 0) { throw new ArgumentException("Record cannot be zero. If this is a new object it should be saved first.", "record"); } item.Active = false; session.Update(item); var alog = session.Query <ActiveLog>().FirstOrDefault(x => x.TableName == tableName && x.Record == record && x.DisableDate == null); if (alog != null) { alog.DisableDate = DateTime.Now.Date.AddDays(1); session.Update(alog); } }
private void OnCellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = ownersView.Rows[e.RowIndex]; object currentValue = row.Cells[e.ColumnIndex].Value; int id = (int)row.Tag; NHibernate.ISession session = obj_lib.Module.OpenSession(); SEPO_TP_WORKSHOP_OWNER dbRow = session.Get <SEPO_TP_WORKSHOP_OWNER>(id); dbRow.OWNER = (int?)currentValue; session.Update(dbRow); session.Flush(); }
private void OnCellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = operationsView.Rows[e.RowIndex]; object currentValue = row.Cells[e.ColumnIndex].Value; int id = (int)row.Tag; NHibernate.ISession session = obj_lib.Module.OpenSession(); SEPO_TECH_OPER_LINKS dbRow = session.Get <SEPO_TECH_OPER_LINKS>(id); dbRow.OMPID = (int?)currentValue; session.Update(dbRow); session.Flush(); }
public void Update(faceboardpro.Domain.Captcha captcha) { try { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { session.Update(captcha.CaptchaService, captcha); transaction.Commit(); } } } catch (Exception ex) { GlobusLogHelper.log.Error("Error : " + ex.StackTrace); } }
public void Update(Email email) { try { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { session.Update(email.UserName, email); transaction.Commit(); } } } catch (Exception ex) { GlobusLogHelper.log.Error("Error : " + ex.StackTrace); } }
/// <summary> /// Update the Particular Data in Table Related to the class /// </summary> public static void Update <A>(A newobject) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { session.Update(newobject); transaction.Commit(); } catch (Exception) { throw; } } } }
//public void SaveOrUpdate(Setting setting) //{ // try // { // using (NHibernate.ISession session = SessionFactory.GetNewSession()) // { // using (NHibernate.ITransaction transaction = session.BeginTransaction()) // { // session.SaveOrUpdate(setting); // transaction.Commit(); // } // } // } // catch (Exception ex) // { // GlobusLogHelper.log.Error("Error : " + ex.StackTrace); // } //} #endregion public void Update(Setting setting) { try { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { session.Update(setting.FilePath, setting); transaction.Commit(); } } } catch (Exception ex) { GlobusLogHelper.log.Error("Error : " + ex.StackTrace); } }
public void Update(WallPosterUnique WPQ) { try { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { session.Update(WPQ.Status, WPQ); transaction.Commit(); } } } catch (Exception ex) { GlobusLogHelper.log.Error("Error : " + ex.StackTrace); } }
public void Update(Account acc) { try { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { session.Update(acc.Password, acc); transaction.Commit(); } } } catch (Exception ex) { GlobusLogHelper.log.Error("Error : " + ex.StackTrace); } }
internal static void Enable(this NHibernate.ISession session, IActiveDataItem item) { if (session == null) { throw new ArgumentNullException("session"); } if (item == null) { throw new ArgumentNullException("item"); } string tableName = item.TableName(); if (!_allowed.Contains(tableName)) { throw new ArgumentException("TableName is invalid.", "tableName"); } int record = item.Record(); if (record == 0) { throw new ArgumentException("Record cannot be zero. If this is a new object it should be saved first.", "record"); } item.Active = true; session.Update(item); var alog = session.Query <ActiveLog>().FirstOrDefault(x => x.TableName == tableName && x.Record == record && x.DisableDate == null); // if an ActiveLog with null DisableDate already exists then there is no reason to create a new one or do anything else if (alog == null) { session.Save(new ActiveLog { DisableDate = null, EnableDate = DateTime.Now.Date, Record = record, TableName = tableName }); } }
public int AddOrUpdate(int id, string endereco, object emails, string name, object phones, string empresa) { try { using (NHibernate.ISessionFactory sessionFactory = SessionFactoryBuilder.BuildSessionFactory()) { using (NHibernate.ISession session = sessionFactory.OpenSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { ContatoEntitis contatoToBeSave = new ContatoEntitis { Id = id, Endereco = endereco, Email = JsonConvert.SerializeObject(emails), Nome = name, Telefone = JsonConvert.SerializeObject(phones), Empresa = empresa }; if (contatoToBeSave.Id > 0) { session.Update(contatoToBeSave); } else { session.Save(contatoToBeSave); } transaction.Commit(); return(contatoToBeSave.Id); } } } } catch (Exception ex) { throw; } }
/// <summary> /// Update the Particular Data in Table Related to the class /// with Filteration /// </summary> public static void UpdateWithCondition <T>(Expression <Func <T, bool> > predicate) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { List <T> _ListT = GetAllByCondition(predicate); foreach (var item in _ListT) { session.Update(item); } transaction.Commit(); } catch (Exception) { throw; } } } }
/// if obj.IsNew, returns any database generated PK, or else the already-assigned PK private object SaveOrUpdateThroughORM(NHibernate.ISession session, IDataObject obj, bool isMainEntity = false) { object newPK = null; var toSave = obj.ToORMEntity(); if (obj.IsNew) { var pk = session.Save(toSave); if (isMainEntity) { newPK = pk; } } else { session.Update(toSave); } return(newPK); }
private void _AddToGroup(NHibernate.ISession session) { var user = session.QueryOver <UserModel>().Where(u => u.UserId == _addToGroupUserId).List().FirstOrDefault(); if (user == null) { throw new InvalidOperationException($"User (UserId: {_addToGroupUserId}) does not exist."); } var group = session.QueryOver <GroupModel>().Where(g => g.GroupId == _addToGroupGroupId).List().FirstOrDefault(); if (group == null) { throw new InvalidOperationException($"Group (GroupId: {_addToGroupGroupId}) does not exist."); } // Zgłoś błąd jeśli użytkownik jest już przypisany do tej grupy. if (user.Groups.Contains(group)) { throw new InvalidOperationException($"User is already in a group: {group.Name}"); } user.Groups.Add(group); session.Update(user); }
private void _Update(NHibernate.ISession session) { session.Update(_resourceToUpdate); }
//TODO:atrosin Revise where and how is used the method public static void LoadHibernateData(ISession session, HandlingEventFactory handlingEventFactory, IHandlingEventRepository handlingEventRepository) { Console.WriteLine("*** Loading Hibernate data ***"); foreach (Location location in SampleLocations.GetAll()) { session.Save(location); } foreach (Voyage voyage in SampleVoyages.GetAll()) { session.Save(voyage); } /*session.Save(SampleVoyages.HONGKONG_TO_NEW_YORK); * session.Save(SampleVoyages.NEW_YORK_TO_DALLAS); * session.Save(SampleVoyages.DALLAS_TO_HELSINKI); * session.Save(SampleVoyages.HELSINKI_TO_HONGKONG); * session.Save(SampleVoyages.DALLAS_TO_HELSINKI_ALT);*/ var routeSpecification = new RouteSpecification(SampleLocations.HONGKONG, SampleLocations.HELSINKI, DateUtil.ToDate("2009-03-15")); var trackingId = new TrackingId("ABC123"); var abc123 = new Cargo(trackingId, routeSpecification); var itinerary = new Itinerary( new List <Leg> { new Leg(SampleVoyages.HONGKONG_TO_NEW_YORK, SampleLocations.HONGKONG, SampleLocations.NEWYORK, DateUtil.ToDate("2009-03-02"), DateUtil.ToDate("2009-03-05")), new Leg(SampleVoyages.NEW_YORK_TO_DALLAS, SampleLocations.NEWYORK, SampleLocations.DALLAS, DateUtil.ToDate("2009-03-06"), DateUtil.ToDate("2009-03-08")), new Leg(SampleVoyages.DALLAS_TO_HELSINKI, SampleLocations.DALLAS, SampleLocations.HELSINKI, DateUtil.ToDate("2009-03-09"), DateUtil.ToDate("2009-03-12")) }); abc123.AssignToRoute(itinerary); session.Save(abc123); HandlingEvent event1 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-01"), trackingId, null, SampleLocations.HONGKONG.UnLocode, HandlingType.RECEIVE ); session.Save(event1); HandlingEvent event2 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-02"), trackingId, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.HONGKONG.UnLocode, HandlingType.LOAD ); session.Save(event2); HandlingEvent event3 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-05"), trackingId, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.NEWYORK.UnLocode, HandlingType.UNLOAD ); session.Save(event3); HandlingHistory handlingHistory = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId); abc123.DeriveDeliveryProgress(handlingHistory); session.Update(abc123); // Cargo JKL567 var routeSpecification1 = new RouteSpecification(SampleLocations.HANGZOU, SampleLocations.STOCKHOLM, DateUtil.ToDate("2009-03-18")); var trackingId1 = new TrackingId("JKL567"); var jkl567 = new Cargo(trackingId1, routeSpecification1); var itinerary1 = new Itinerary(new List <Leg> { new Leg(SampleVoyages.HONGKONG_TO_NEW_YORK, SampleLocations.HANGZOU, SampleLocations.NEWYORK, DateUtil.ToDate("2009-03-03"), DateUtil.ToDate("2009-03-05")), new Leg(SampleVoyages.NEW_YORK_TO_DALLAS, SampleLocations.NEWYORK, SampleLocations.DALLAS, DateUtil.ToDate("2009-03-06"), DateUtil.ToDate("2009-03-08")), new Leg(SampleVoyages.DALLAS_TO_HELSINKI, SampleLocations.DALLAS, SampleLocations.STOCKHOLM, DateUtil.ToDate("2009-03-09"), DateUtil.ToDate("2009-03-11")) }); jkl567.AssignToRoute(itinerary1); session.Save(jkl567); HandlingEvent event21 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-01"), trackingId1, null, SampleLocations.HANGZOU.UnLocode, HandlingType.RECEIVE); session.Save(event21); HandlingEvent event22 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-03"), trackingId1, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.HANGZOU.UnLocode, HandlingType.LOAD ); session.Save(event22); HandlingEvent event23 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-05"), trackingId1, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.NEWYORK.UnLocode, HandlingType.UNLOAD ); session.Save(event23); HandlingEvent event24 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-06"), trackingId1, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.NEWYORK.UnLocode, HandlingType.LOAD ); session.Save(event24); HandlingHistory handlingHistory1 = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId1); jkl567.DeriveDeliveryProgress(handlingHistory1); session.Update(jkl567); }
//TODO:atrosin Revise where and how is used the method public static void LoadHibernateData(ISession session, HandlingEventFactory handlingEventFactory, IHandlingEventRepository handlingEventRepository) { Console.WriteLine("*** Loading Hibernate data ***"); foreach (Location location in SampleLocations.GetAll()) { session.Save(location); } foreach (Voyage voyage in SampleVoyages.GetAll()) { session.Save(voyage); } /*session.Save(SampleVoyages.HONGKONG_TO_NEW_YORK); session.Save(SampleVoyages.NEW_YORK_TO_DALLAS); session.Save(SampleVoyages.DALLAS_TO_HELSINKI); session.Save(SampleVoyages.HELSINKI_TO_HONGKONG); session.Save(SampleVoyages.DALLAS_TO_HELSINKI_ALT);*/ var routeSpecification = new RouteSpecification(SampleLocations.HONGKONG, SampleLocations.HELSINKI, DateUtil.ToDate("2009-03-15")); var trackingId = new TrackingId("ABC123"); var abc123 = new Cargo(trackingId, routeSpecification); var itinerary = new Itinerary( new List<Leg> { new Leg(SampleVoyages.HONGKONG_TO_NEW_YORK, SampleLocations.HONGKONG, SampleLocations.NEWYORK, DateUtil.ToDate("2009-03-02"), DateUtil.ToDate("2009-03-05")), new Leg(SampleVoyages.NEW_YORK_TO_DALLAS, SampleLocations.NEWYORK, SampleLocations.DALLAS, DateUtil.ToDate("2009-03-06"), DateUtil.ToDate("2009-03-08")), new Leg(SampleVoyages.DALLAS_TO_HELSINKI, SampleLocations.DALLAS, SampleLocations.HELSINKI, DateUtil.ToDate("2009-03-09"), DateUtil.ToDate("2009-03-12")) }); abc123.AssignToRoute(itinerary); session.Save(abc123); HandlingEvent event1 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-01"), trackingId, null, SampleLocations.HONGKONG.UnLocode, HandlingType.RECEIVE ); session.Save(event1); HandlingEvent event2 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-02"), trackingId, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.HONGKONG.UnLocode, HandlingType.LOAD ); session.Save(event2); HandlingEvent event3 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-05"), trackingId, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.NEWYORK.UnLocode, HandlingType.UNLOAD ); session.Save(event3); HandlingHistory handlingHistory = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId); abc123.DeriveDeliveryProgress(handlingHistory); session.Update(abc123); // Cargo JKL567 var routeSpecification1 = new RouteSpecification(SampleLocations.HANGZOU, SampleLocations.STOCKHOLM, DateUtil.ToDate("2009-03-18")); var trackingId1 = new TrackingId("JKL567"); var jkl567 = new Cargo(trackingId1, routeSpecification1); var itinerary1 = new Itinerary(new List<Leg> { new Leg(SampleVoyages.HONGKONG_TO_NEW_YORK, SampleLocations.HANGZOU, SampleLocations.NEWYORK, DateUtil.ToDate("2009-03-03"), DateUtil.ToDate("2009-03-05")), new Leg(SampleVoyages.NEW_YORK_TO_DALLAS, SampleLocations.NEWYORK, SampleLocations.DALLAS, DateUtil.ToDate("2009-03-06"), DateUtil.ToDate("2009-03-08")), new Leg(SampleVoyages.DALLAS_TO_HELSINKI, SampleLocations.DALLAS, SampleLocations.STOCKHOLM, DateUtil.ToDate("2009-03-09"), DateUtil.ToDate("2009-03-11")) }); jkl567.AssignToRoute(itinerary1); session.Save(jkl567); HandlingEvent event21 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-01"), trackingId1, null, SampleLocations.HANGZOU.UnLocode, HandlingType.RECEIVE); session.Save(event21); HandlingEvent event22 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-03"), trackingId1, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.HANGZOU.UnLocode, HandlingType.LOAD ); session.Save(event22); HandlingEvent event23 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-05"), trackingId1, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.NEWYORK.UnLocode, HandlingType.UNLOAD ); session.Save(event23); HandlingEvent event24 = handlingEventFactory.CreateHandlingEvent( new DateTime(), DateUtil.ToDate("2009-03-06"), trackingId1, SampleVoyages.HONGKONG_TO_NEW_YORK.VoyageNumber, SampleLocations.NEWYORK.UnLocode, HandlingType.LOAD ); session.Save(event24); HandlingHistory handlingHistory1 = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId1); jkl567.DeriveDeliveryProgress(handlingHistory1); session.Update(jkl567); }