Example #1
0
        public ActionResult UpdateToOrders(string type, string id, string mode)
        {
            try
            {
                ViewBag.Type = type;
                ViewBag.Mode = mode;

                if (type == "buy")
                {
                    ViewBag.Element = manager.GetContext().BuyOrders.Find(Convert.ToInt32(id));
                }
                else
                {
                    ViewBag.Element = manager.GetContext().ReadingOrders.Find(Convert.ToInt32(id));
                }

                Book book = manager.GetContext().Lib.Find(ViewBag.Element.Id_book);
                ViewBag.Id_empl  = manager.GetContext().Employees.Find(ViewBag.Element.Id_employee).Id;
                ViewBag.Employee = manager.GetContext().Employees.Find(ViewBag.Element.Id_employee).FIO;
                ViewBag.Books    = manager.GetContext().Lib;
                List <string> names = new List <string>();
                foreach (var em in manager.GetContext().Employees)
                {
                    names.Add(em.FIO);
                }
                ViewBag.ListEmployees = names;
                ViewBag.BookName      = book.Book_title;
                ViewBag.Short_desc    = book.Short_description;
                if (mode == "delete")
                {
                    if (type == "buy")
                    {
                        var order      = manager.GetContext().BuyOrders.Find(Convert.ToInt32(Request.Params["id"]));
                        var innerCount = manager.GetContext().ReadingOrders.Where(s => s.Id_book == order.Id_book);
                        if (innerCount.Count() > 0)
                        {
                            foreach (var el in innerCount)
                            {
                                DeleteHelper.FromReadingOrder(el.Id);
                            }
                        }
                        DeleteHelper.FromBuyOrder(order.Id);
                        DeleteHelper.FromBook(manager.GetContext().Lib.Find(order.Id_book).Id);
                    }
                    else
                    {
                        DeleteHelper.FromReadingOrder(Convert.ToInt32(id));
                    }
                    string message = "Запись удалена";
                    Response.Redirect("/Home/Orders?message=" + message + "&type=" + type);
                }
                return(View());
            }
            catch (Exception ex)
            {
                string message = "Не удалось обновить запись";
                Response.Redirect("/Home/Orders?message=" + message + "&type=" + type);
                return(View());
            }
        }
Example #2
0
        public void ReadBook()
        {
            try
            {
                var      type     = Request.Params["Type"];
                var      name     = Request.Params["selection"];
                var      idBook   = Convert.ToInt32(Request.Params["Id_book"]);
                string   message  = "";
                Employee employee = manager.GetContext().Employees.Where(s => s.FIO == name).FirstOrDefault();
                Book     book     = manager.GetContext().Lib.Find(idBook);
                var      issBook  = manager.GetContext().IssuedBooks.Where(s => s.Id_book == idBook);

                if (type == "read,")
                {
                    if (book.Number_copies - issBook.Count() > 0)
                    {
                        message += UpdateHelper.FromEmployee(employee.Id, employee.Department, employee.FIO, employee.Phone, employee.Read_books + 1);
                        message += InsertHelper.FromIssued(idBook, employee.Id, DateTime.Now.AddDays(15).ToString());
                        var d = manager.GetContext().ReadingOrders.Where(s => s.Id_employee == employee.Id);
                        if (d != null)
                        {
                            foreach (var b in d)
                            {
                                if (b.Id_book == idBook)
                                {
                                    DeleteHelper.FromReadingOrder(b.Id);
                                }
                            }
                        }
                    }
                    else
                    {
                        message = "В данный момент нет свободных книг. Вы можете оформить заказ на чтение";
                    }
                }
                else if (type == "order,")
                {
                    message = InsertHelper.FromReadingOrder(employee.Id, Convert.ToInt32(idBook));
                }

                Response.Redirect("/Home/Read?message=" + message);
            }
            catch (Exception ex)
            {
                Response.Redirect("/Home/Read?message=" + ex.Message);
            }
        }