예제 #1
0
        protected void Insert(object sender, EventArgs e)
        {
            try
            {
                BookBL bookBL = new BookBL();
                BookBO book   = new BookBO();

                book = GetBookObject(book);


                bookTable = (List <BookBO>)Session[Common.sessionBookList];
                if (bookTable == null)
                {
                    bookTable = new List <BookBO>();
                }

                bookTable = bookBL.Add(book, bookTable);

                Session[Common.sessionBookList] = bookTable;

                Session["bookId"] = book.Id + 1;

                gvBookList.EditIndex = -1;
                FillGrid();

                lblSuccessMessage.Text = Common.msgAddSuccess;
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = Common.msgAddFailure;
            }
        }
예제 #2
0
        private BookBO GetUpdateObject(BookBO book, int index)
        {
            bookTable = (List <BookBO>)Session[Common.sessionBookList];
            TextBox txtName  = (TextBox)gvBookList.Rows[index].FindControl("txtName");
            TextBox txtPrice = (TextBox)gvBookList.Rows[index].FindControl("txtPrice");

            book.Name  = string.IsNullOrEmpty(txtName.Text) == true ? string.Empty : txtName.Text.Trim();
            book.Price = string.IsNullOrEmpty(txtPrice.Text) == true ? 0 : Convert.ToDouble(txtPrice.Text.Trim());
            book.Id    = Convert.ToInt32(gvBookList.DataKeys[index].Values[0]);
            return(book);
        }
예제 #3
0
 public List <BookBO> Update(BookBO book, List <BookBO> books) // passing Bussiness object Here
 {
     try
     {
         BookDA bookDA = new BookDA();
         return(bookDA.Update(book, books));
     }
     catch
     {
         throw;
     }
 }
예제 #4
0
 public List <BookBO> Add(BookBO book, List <BookBO> books) // Data Access Layer // passing Bussiness object Here
 {
     try
     {
         BookDA bookDA = new BookDA();
         // GetNextHighestBookId
         return(bookDA.Add(book, books));
     }
     catch
     {
         throw;
     }
 }
예제 #5
0
 private BookBO GetBookObject(BookBO book)
 {
     try
     {
         book.Name  = string.IsNullOrEmpty(txtName.Text) == true ? string.Empty : txtName.Text.Trim();
         book.Price = string.IsNullOrEmpty(txtPrice.Text) == true ? 0 : Convert.ToDouble(txtPrice.Text.Trim());
         book.Id    = (int)Session["bookId"];
         return(book);
     }
     catch (Exception ex)
     {
         lblErrorMessage.Text = Common.msgAddFailure;
         return(null);
     }
 }
예제 #6
0
        protected void gvBookList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                BookBL bookBL = new BookBL();
                BookBO book   = new BookBO();
                book = GetUpdateObject(book, e.RowIndex);

                bookTable = bookBL.Update(book, bookTable);

                Session[Common.sessionBookList] = bookTable;
                gvBookList.EditIndex            = -1;
                FillGrid();
                lblSuccessMessage.Text = Common.msgUpdateSuccess;
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = Common.msgUpdateFailure;
            }
        }
예제 #7
0
        public ActionResult Index()
        {
            var authorBO   = DependencyResolver.Current.GetService <AuthorBO>();
            var authorList = authorBO.GetAuthorsList().OrderBy(n => n.LastName);

            ViewBag.Authors = authorList.Select(x => mapper.Map <AuthorView>(x)).ToList();

            List <AuthorView> topAuthor = new List <AuthorView>();
            BookBO            books     = DependencyResolver.Current.GetService <BookBO>();
            var expensive = books.GetBooksList().Select(item => mapper.Map <BookView>(item)).OrderByDescending(b => b.Price).ToList();

            foreach (var item in expensive)
            {
                topAuthor.Add(authorList.Select(a => mapper.Map <AuthorView>(a)).Where(a => a.Id == item.AuthorId).FirstOrDefault());
            }


            ViewBag.AuthorsTop = topAuthor.Distinct().Take(5);

            return(View());
        }
예제 #8
0
        public ActionResult Index()
        {
            var authorBO   = DependencyResolver.Current.GetService <AuthorBO>();
            var authorList = authorBO.GetAuthorsList().OrderBy(n => n.LastName); //сортировка по фамилии в алфавитном порядке

            ViewBag.Authors = authorList.Select(a => mapper.Map <AuthorViewModel>(a)).ToList();

            List <AuthorViewModel> authorsTop = new List <AuthorViewModel>();
            BookBO booksBO = DependencyResolver.Current.GetService <BookBO>();

            //топ 5 авторов
            var expensiveBooks = booksBO.GetBooksList().OrderByDescending(b => b.Price).Select(x => mapper.Map <BookViewModel>(x)).ToList();

            expensiveBooks.ForEach(
                x =>
            {
                authorsTop.Add(authorList.Select(m => mapper.Map <AuthorViewModel>(m)).Where(a => a.Id == x.AuthorId).FirstOrDefault());
            });
            ViewBag.ListTopAuthors = authorsTop.Distinct().Take(5);

            return(View());
        }
예제 #9
0
        public bool Delete(Guid id)
        {
            base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
            var fileBO = new FileBO();
            var bookBO = new BookBO();

            try
            {
                var book = bookBO.Get(base.ConnectionHandler, id);
                if (book.Image != null && book.Image != Guid.Empty)
                {
                    if (!fileBO.Delete(base.ConnectionHandler, book.Image))
                    {
                        throw new Exception("خطایی در حذف اطلاعات کتاب رخ داده است");
                    }
                }
                if (book.PDF != null && book.PDF != Guid.Empty)
                {
                    if (!fileBO.Delete(base.ConnectionHandler, book.PDF))
                    {
                        throw new Exception("خطایی در حذف اطلاعات کتاب رخ داده است");
                    }
                }
                if (!bookBO.Delete(base.ConnectionHandler, book))
                {
                    throw new Exception("خطایی در حذف اطلاعات کتاب رخ داده است");
                }

                base.ConnectionHandler.CommitTransaction();
                return(true);
            }
            catch (Exception ex)
            {
                base.ConnectionHandler.RollBack();
                throw new Exception(ex.Message, ex);
            }
        }
예제 #10
0
        public bool InsertPayment(Guid bookId, Guid customerId, long number)
        {
            base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
            var book = new BookBO().Get(base.ConnectionHandler, bookId);
            var sum  = book.Discount > 0 ? book.Price.Value - (book.Price.Value * book.Discount / 100) : book.Price.Value;

            try
            {
                var customerBook = new CustomerBook()
                {
                    BookId     = bookId,
                    CustomerId = customerId,
                    VIP        = true
                };
                if (!new CustomerBookBO().Insert(base.ConnectionHandler, customerBook))
                {
                    throw new KnownException("خطا در ذخیره اطلاعات");
                }
                var order = new Order()
                {
                    Number      = number,
                    OrderDate   = DateTime.Now.ShamsiDate(),
                    TotalAmount = book.Price.Value,
                    Discount    = book.Discount,
                    Amount      = sum,
                    Status      = PaymentStatus.Success,
                    CustomerId  = customerId,
                    BookId      = bookId
                };
                if (!new OrderBO().Insert(base.ConnectionHandler, order))
                {
                    throw new KnownException("خطا در ذخیره اطلاعات");
                }
                var peyment = new Payment()
                {
                    Number        = number,
                    OrderId       = order.Id,
                    Amount        = sum,
                    PaymentDate   = DateTime.Now.ShamsiDate(),
                    PaymentStatus = PaymentStatus.Success,
                    PaymentType   = PaymentType.Online,
                    PaymentRole   = PaymentRole.Success,
                    AuthorId      = book.AuthorId,
                    CustomerId    = customerId
                };
                if (!new PaymentBO().Insert(base.ConnectionHandler, peyment))
                {
                    throw new KnownException("خطا در ذخیره اطلاعات");
                }
                var walletBo = new WalletBO();
                var amount   = sum * book.Percent / 100;
                var wa       = new Wallet()
                {
                    AuthorId = book.AuthorId,
                    Amount   = amount,
                    Input    = amount,
                    Number   = number,
                    BookId   = bookId
                };
                if (!walletBo.Insert(base.ConnectionHandler, wa))
                {
                    throw new KnownException("خطا در ذخیره اطلاعات");
                }

                base.ConnectionHandler.CommitTransaction();
                return(true);
            }
            catch (Exception ex)
            {
                base.ConnectionHandler.RollBack();
                throw new KnownException(ex.Message);
            }
        }