Exemplo n.º 1
0
        public Book Save(Database db, Guid userID)
        {
            _UserID = userID;
            Boolean result = true;

            if (base.IsNew == true && IsSavable() == true)
            {
                result = Insert(db);

                UserBook ub = new UserBook();
                ub.UserID  = userID;
                _UserBooks = new UserBookList();
                _UserBooks.List.Add(ub);
            }
            else if (base.Deleted == true)
            {
                result = Delete(db);
            }
            else if (base.IsNew == false && IsSavable() == true)
            {
                result = Update(db);
            }

            base.IsDirty = false;
            base.IsNew   = false;

            if (result == true && _UserBooks != null && _UserBooks.IsSavable() == true)
            {
                result = _UserBooks.Save(db, userID, base.ID);
            }

            return(this);
        }
Exemplo n.º 2
0
        public User Save()
        {
            Database db = new Database("Books");

            db.BeginTransaction();
            Boolean result = true;

            if (base.IsNew == true && IsSavable() == true)
            {
                result = Insert(db);
            }
            else if (base.Deleted == true)
            {
                result = Delete(db);
            }
            else if (base.IsNew == false && IsSavable() == true)
            {
                result = Update(db);
            }

            base.IsDirty = false;
            base.IsNew   = false;

            if (result == true && _books != null && _books.IsSavable() == true)
            {
                result = _books.Save(db, base.ID);
            }

            if (result == true && _userbooks != null && _userbooks.IsSavable() == true)
            {
                result = _userbooks.Save(db, _userbooks.List[_userbooks.List.Count - 1].UserID, _userbooks.List[_userbooks.List.Count - 1].BookID);
            }

            if (result == true)
            {
                db.EndTransaction();
            }
            else
            {
                db.RollBackTransaction();
            }
            return(this);
        }