コード例 #1
0
        public BookCategory Update(BookCategory t)
        {
            BookCategory f = Get(t.Id);

            if (f == null)
            {
                throw new ArgumentNullException($"BookCategory Item with id {t.Id} does not exist or its deleted");
            }

            bookCategory.Remove(t);

            if (!IsDuplicate(t))
            {
                if (t.Id <= 0)
                {
                    throw new ArgumentException("Invalid BookCategory Item Id");
                }

                f.CategoryName = t.CategoryName;
                f.Quantity     = t.Quantity;


                f = DbStore.Save <BookCategory>(f);

                return(f);
            }
            else
            {
                bookCategory.Add(f);
                throw new DuplicateItemException("BookCategory Item already exists");
            }
        }
コード例 #2
0
        public void Delete(long id)
        {
            BookCategory r = Get(id);

            DbStore.Delete <BookCategory>(r);
            bookCategory.Remove(r);
        }
コード例 #3
0
        public BookCategory Add(BookCategory t)
        {
            if (!IsDuplicate(t))
            {
                t.Id = 0;
                var ret = DbStore.Save <BookCategory>(t);

                if (ret != null)
                {
                    bookCategory.Add(ret);
                }

                return(ret);
            }
            else
            {
                throw new DuplicateItemException("Book Category already exists");
            }
        }
コード例 #4
0
 bool IsDuplicate(BookCategory r)
 {
     return(bookCategory.Exists(d => (d.CategoryName == r.CategoryName && d.Quantity == r.Quantity)));
 }