コード例 #1
0
ファイル: PageController.cs プロジェクト: andrewchaa/bookwarm
        // POST api/page
        public void Post(Reading reading)
        {
            if (string.IsNullOrEmpty(reading.Title))
                return;

            reading.LastUpdate = DateTime.UtcNow;
            _repository.Save(reading);
        }
コード例 #2
0
        public void Save(Reading readingToSave)
        {
            using (var session = NHibernateHelper.OpenSession())
            using (var transaction = session.BeginTransaction())
            {
                var reading = session.CreateCriteria<Reading>()
                    .Add(Restrictions.Eq("UserName", readingToSave.UserName))
                    .Add(Restrictions.Eq("Title", readingToSave.Title))
                    .UniqueResult<Reading>();

                if (reading != null)
                {
                    reading.PageNumber = readingToSave.PageNumber;
                    reading.LastUpdate = readingToSave.LastUpdate;
                    session.Update(reading);
                }
                else
                {
                    session.Save(readingToSave);
                }
                transaction.Commit();
            }
        }