Beispiel #1
0
        // POST api/page
        public void Post(Reading reading)
        {
            if (string.IsNullOrEmpty(reading.Title))
                return;

            reading.LastUpdate = DateTime.UtcNow;
            _repository.Save(reading);
        }
        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();
            }
        }