Beispiel #1
0
 public static void ChangeBook(BookModel bm, int amount)
 {
     using (var context = new librarydbEntities())
     {
         book   b    = context.books.Single(bk => bk.isbn == bm.isbn);
         var    am   = bm.author;
         author auth = context.authors.Single(au => au.name == am.name && au.birth_year == am.age);
         if (auth == null)
         {
             auth = new author
             {
                 birth_year = am.age,
                 name       = am.name,
                 bio        = "Bio"
             };
             context.authors.Add(auth);
             context.SaveChanges();
         }
         b.name        = bm.name;
         b.author      = auth;
         b.amount      = amount;
         b.depositCost = bm.depositCost;
         b.description = bm.description;
         b.isbn        = bm.isbn;
         b.rentCost    = bm.rentCost;
         b.year        = bm.year;
         b.jenres      = string.Join(",", bm.jenres);
         b.pages       = bm.pages;
         context.SaveChanges();
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            librarydbEntities db = new librarydbEntities();

            /*var que = (from mat in db.materials
             *          join t in db.types on mat.typeID equals t.typeID
             *          group t by mat into g
             *          select new
             *          {
             *              Name=g.Key.type.typeName,
             *
             *          }
             *
             *        ).;*/
            var results = db.materials.Where(r => r.matID != null)
                          .GroupBy(r => r.type.typeName)
                          .Select(gr => new { Key = gr.Key, Count = gr.Count() })
                          .ToList();
            //  GridView1.DataSource = results;
            // GridView1.DataBind();


            /*foreach(var mat in results)
             * // ChartMaterial.Series
             * ChartMaterial.DataSource = results;
             * ChartMaterial.DataBind();*/
        }
Beispiel #3
0
 public static void AddBook(BookModel book)
 {
     using (var context = new librarydbEntities())
     {
         var    am   = book.author;
         author auth = context.authors.Single(au => au.name == am.name && au.birth_year == am.age);
         if (auth == null)
         {
             auth = new author
             {
                 birth_year = am.age,
                 name       = am.name,
                 bio        = "Bio"
             };
             context.authors.Add(auth);
             context.SaveChanges();
         }
         context.books.Add(new book
         {
             amount      = 1,
             name        = book.name,
             author      = auth,
             depositCost = book.depositCost,
             description = book.description,
             isbn        = book.isbn,
             rentCost    = book.rentCost,
             year        = book.year,
             jenres      = string.Join(",", book.jenres),
             pages       = book.pages
         });
         context.SaveChanges();
     }
 }
Beispiel #4
0
 public static void RemoveBook(string isbn)
 {
     using (var context = new librarydbEntities())
     {
         book b = context.books.Single(bk => bk.isbn == isbn);
         context.books.Remove(b);
         context.SaveChanges();
     }
 }
Beispiel #5
0
 public static void IncreaseAmount(string isbn, int delta)
 {
     using (var context = new librarydbEntities())
     {
         book b = context.books.Single(bk => bk.isbn == isbn);
         b.amount += delta;
         context.SaveChanges();
     }
 }
Beispiel #6
0
 public static void CompleteOffer(OfferModel offer)
 {
     using (var context = new librarydbEntities())
     {
         var off = context.offers.Single(of => of.id == offer.id);
         off.status = "Completed";
         context.SaveChanges();
     }
 }
Beispiel #7
0
        void show()
        {
            librarydbEntities db = new librarydbEntities();

            var sqlQuery = (from mat in db.materials
                            join t in db.types on mat.typeID equals t.typeID
                            join p in db.publishers on mat.publisherID equals p.pubID
                            join c in db.categories on mat.catID equals c.catID
                            join b in db.branches on mat.branchID equals b.branchID
                            join l in db.languages on mat.langID equals l.langID
                            join au in db.aus on mat.matID equals au.matID
                            join aut in db.authors on au.authorID equals aut.authorID
                            group aut by mat into g
                            select new
            {
                SSN = g.Key.matID,
                Name = g.Key.name,
                Title = g.Key.title,
                TypeB = g.Key.type.typeName,
                Category = g.Key.category.catName,
                Author = g.Select(si => si.name),
                //Surname=g.Select(sir=>sir.surname),
                Language = g.Key.language.langName,
                Publisher = g.Key.publisher.publisherName,
                Branch = g.Key.branch.branchName,
                Price = g.Key.price,
                PageNo = g.Key.pageNo,
                Descripton = g.Key.description,
                Avaible = g.Key.avaible
            }

                            ).ToList().Select(x => new
            {
                x.SSN,
                x.Name,
                x.Title,
                x.TypeB,
                x.Category,
                Authors = string.Join(",", x.Author)
                ,
                x.Language,
                x.Publisher,
                x.Branch,
                x.Price,
                x.PageNo,
                x.Descripton
                ,
                x.Avaible
            }).OrderByDescending(m => m.SSN).Take(15);


            gridLatestMaterial.DataSource = sqlQuery;
            gridLatestMaterial.DataBind();
        }
Beispiel #8
0
 public static void AddRequest(BookRequestModel request)
 {
     using (var context = new librarydbEntities())
     {
         context.requests.Add(new request
         {
             book   = context.books.Single(bk => bk.isbn == request.book.isbn),
             client = context.clients.Single(cl => cl.clientId == request.client.card.id),
         });
         context.SaveChanges();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         librarydbEntities db = new librarydbEntities();
         DropDownMembers.DataTextField = "UserName";
         DropDownMembers.DataSource    = Membership.GetAllUsers();
         DropDownMembers.DataBind();
         DropDownRoles.DataSource = Roles.GetAllRoles();
         DropDownRoles.DataBind();
     }
 }
Beispiel #10
0
 public static void AddOffer(OfferModel offer)
 {
     using (var context = new librarydbEntities())
     {
         context.offers.Add(new offer
         {
             status   = offer.status.ToString(),
             deadline = Convert.ToString(offer.returnDate),
             book     = context.books.Single(bk => bk.isbn == offer.book.isbn),
             client   = context.clients.Single(cl => cl.clientId == offer.client.card.id),
         });
         context.SaveChanges();
     }
 }
Beispiel #11
0
 public static void AddClient(ClientModel client)
 {
     using (var context = new librarydbEntities())
     {
         context.clients.Add(new client
         {
             name     = client.name,
             age      = (int)client.birth_year,
             balance  = client.balance,
             login    = client.login,
             password = client.password,
         });
         context.SaveChanges();
     }
 }
        void show()
        {
            librarydbEntities db = new librarydbEntities();

            //Fill Branch DropDown
            dropDownListBranch.DataSource     = db.branches.ToList();
            dropDownListBranch.DataValueField = "branchID";
            dropDownListBranch.DataTextField  = "branchName";
            dropDownListBranch.DataBind();
            ListItem litem9 = new ListItem();

            litem9.Text  = "All Branches";
            litem9.Value = "0";
            dropDownListBranch.Items.Add(litem9);
            dropDownListBranch.SelectedValue = litem9.Value.ToString();
            //Fill Catalog DropDown
            dropDownListCatalog.DataSource     = db.types.ToList();
            dropDownListCatalog.DataValueField = "typeID";
            dropDownListCatalog.DataTextField  = "typeName";
            dropDownListCatalog.DataBind();
            ListItem litem8 = new ListItem();

            litem8.Text  = "All Catalogs";
            litem8.Value = "0";
            dropDownListCatalog.Items.Add(litem8);
            dropDownListCatalog.SelectedValue = litem8.Value.ToString();
            //Fill Language DropDown
            dropDownListLanguage.DataSource     = db.languages.ToList();
            dropDownListLanguage.DataValueField = "langID";
            dropDownListLanguage.DataTextField  = "langName";
            dropDownListLanguage.DataBind();
            ListItem litem7 = new ListItem();

            litem7.Text  = "All Languages";
            litem7.Value = "0";
            dropDownListLanguage.Items.Add(litem7);
            dropDownListLanguage.SelectedValue = litem7.Value.ToString();
            //Fill Index DropDown
            ListItem litem = new ListItem();

            litem.Text  = "Keywords";
            litem.Value = "keywords";
            dropDownListIndex.Items.Add(litem);
            ListItem litem2 = new ListItem();

            litem2.Text  = "Author";
            litem2.Value = "author";
            dropDownListIndex.Items.Add(litem2);
            ListItem litem3 = new ListItem();

            litem3.Text  = "Title";
            litem3.Value = "title";
            dropDownListIndex.Items.Add(litem3);
            ListItem litem4 = new ListItem();

            litem4.Text  = "Publisher";
            litem4.Value = "publisher";
            dropDownListIndex.Items.Add(litem4);
            ListItem litem5 = new ListItem();

            litem5.Text  = "Categories";
            litem5.Value = "categories";
            dropDownListIndex.Items.Add(litem5);
        }
Beispiel #13
0
        public static ArchiveModel LoadFromDb()
        {
            ArchiveModel model = new ArchiveModel();

            using (var context = new librarydbEntities())
            {
                var authors  = context.authors.ToList();
                var books    = context.books.ToList();
                var clients  = context.clients.ToList();
                var offers   = context.offers.ToList();
                var requests = context.requests.ToList();
                foreach (var book in books)
                {
                    BookModel bm = BookModelFromEntity(book);
                    model.books.Add(bm.isbn, bm);
                    model.amounts[bm.isbn] = (int)book.amount;
                }
                foreach (var client in clients)
                {
                    ClientModel cm = new ClientModel
                    {
                        birth_year = client.age,
                        balance    = client.balance,
                        card       = new ClientCardModel
                        {
                            completedOffers = client.offers.Where(off => off.status == "Completed").Select(off => off.id).ToList(),
                            pendingOffers   = client.offers.Where(off => off.status == "Pending").Select(off => off.id).ToList(),
                            id       = client.clientId,
                            requests = client.requests.Select(req => req.idRequests).ToList()
                        },
                        login    = client.login,
                        password = client.password,
                        name     = client.name,
                        sex      = "male"
                    };
                    model.clients.Add(cm.card.id, cm);
                }
                foreach (var request in requests)
                {
                    BookRequestModel br = new BookRequestModel
                    {
                        id     = request.idRequests,
                        book   = model.books[request.book.isbn],
                        client = model.clients[request.client_id]
                    };
                    model.requests.Add(br);
                }
                foreach (var offer in offers)
                {
                    OfferModel off = new OfferModel
                    {
                        id         = offer.id,
                        returnDate = Convert.ToDateTime(offer.deadline),
                        status     = (OfferStatus)Enum.Parse(typeof(OfferStatus), offer.status),
                        book       = model.books[offer.book.isbn],
                        client     = model.clients[offer.client_id]
                    };
                    if (off.status == OfferStatus.Completed)
                    {
                        model.completedOffers.Add(off.id, off);
                    }
                    else if (off.status == OfferStatus.Pending)
                    {
                        model.pendingOffers.Add(off.id, off);
                    }
                }
            }
            return(model);
        }