Пример #1
0
 public bool Update(RoleBindingModel model)
 {
     try
     {
         using (var libraryDb = new LibraryManagementEntities())
         {
             // Check first get item
             var role = libraryDb.Roles.FirstOrDefault(s => s.Id == model.Id);
             if (role == null)
             {
                 throw new ArgumentNullException("No exist");
             }
             role.Name = model.Name;
             libraryDb.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Update(SpecialCategoryBindingModel model)
 {
     try
     {
         using (var libraryDb = new LibraryManagementEntities())
         {
             // Check first get item
             var specialCategory = libraryDb.SpecialCategories.FirstOrDefault(s => s.Id == model.Id);
             if (specialCategory == null)
             {
                 throw new ArgumentNullException("No exist");
             }
             specialCategory.Name        = model.Name;
             specialCategory.Description = model.Description;
             libraryDb.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
        public List <ReportModel> Report()
        {
            List <ReportModel> listRs = new List <ReportModel>();

            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    var qry = from a in libraryDb.Categories
                              select a;



                    foreach (var item in qry.ToList())
                    {
                        // Select cout sach where category
                        var s = from a in libraryDb.Books
                                where a.CategoryId == item.Id
                                select a;


                        listRs.Add(new ReportModel()
                        {
                            Category  = item.Name,
                            BookCount = s.Count().ToString(),
                            PageCount = s.Sum(m => m.PageCount).ToString()
                        });
                    }
                }

                return(listRs);
            }
            catch (Exception)
            {
                return(listRs);
            }
        }
Пример #4
0
        public bool UpdateStatusForBorrow(string bookId)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // Check first get item
                    var book = libraryDb.Books.FirstOrDefault(s => s.Id.Equals(bookId));
                    if (book == null)
                    {
                        throw new ArgumentNullException("No exist");
                    }

                    book.Status = SystemConstants.Borrowed;

                    libraryDb.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #5
0
        public static void ChangeLanguage(string language)
        {
            LibraryManagementEntities db = new LibraryManagementEntities();

            switch (language)
            {
            case "Fr":
                IDLanguage = 1;
                break;

            case "En":
                IDLanguage = 2;
                break;

            default:
                IDLanguage = 1;
                break;
            }
            Settings config = db.Settings.Single();

            config.IDLanguage      = IDLanguage;
            db.Entry(config).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #6
0
 public BookManagement()
 {
     this.entities = new LibraryManagementEntities();
 }
        //public ListResult<CategoryBindingModel> GetList(int? specializedId = null, string name = "", int? pageNumber = 0, int? pageSize = 0)
        //{
        //    try
        //    {
        //        using (var libraryDb = new LibraryManagementEntities())
        //        {
        //            var qry = from a in libraryDb.Categories
        //                      select a;

        //            if (!string.IsNullOrWhiteSpace(name))
        //                qry = from a in qry
        //                      where a.Name.Contains(name)
        //                      select a;

        //            if (specializedId != null && specializedId >= 1)
        //                qry = from a in qry
        //                      where a.SpecializedId == specializedId
        //                      select a;

        //            var listRs = ListResult<Category>.GetDataPage(qry.OrderBy(x=>x.Name), pageNumber, pageSize);
        //            if (listRs == null) throw new ArgumentNullException();

        //            if (listRs.ListOfObjects == null) return new ListResult<CategoryBindingModel>();

        //            var listResult = new ListResult<CategoryBindingModel>();
        //            listResult.ListOfObjects = new List<CategoryBindingModel>();
        //            listResult.TotalRecord = listRs.TotalRecord;

        //            foreach (var item in listRs.ListOfObjects)
        //            {
        //                var category = _entityMapper.Map<Category, CategoryBindingModel>(item);
        //                listResult.ListOfObjects.Add(category);
        //            }
        //            return listResult;
        //        }
        //    }
        //    catch (Exception)
        //    {
        //        throw;
        //    }
        //}


        public ListResult <CategoryViewModel> GetList(int?specializedId = null, string name = "", int?pageNumber = 0, int?pageSize = 0)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    var qry = from a in libraryDb.Categories join b in libraryDb.Specializeds
                              on a.SpecializedId equals b.Id
                              select new {
                        Id            = a.Id,
                        Name          = a.Name,
                        SpecializedId = a.SpecializedId,
                        Specialized   = b.Name
                    };

                    if (!string.IsNullOrWhiteSpace(name))
                    {
                        qry = from a in qry
                              where a.Name.Contains(name)
                              select a;
                    }

                    if (specializedId != null && specializedId >= 1)
                    {
                        qry = from a in qry
                              where a.SpecializedId == specializedId
                              select a;
                    }

                    List <CategoryViewModel> LR = new List <CategoryViewModel>();
                    foreach (var item in qry.ToList())
                    {
                        LR.Add(new CategoryViewModel()
                        {
                            Id            = item.Id,
                            Name          = item.Name,
                            SpecializedId = item.SpecializedId,
                            Specialized   = item.Specialized
                        });
                    }

                    var listRs = ListResult <CategoryViewModel> .GetDataPage(LR.OrderBy(x => x.Name), pageNumber, pageSize);

                    if (listRs == null)
                    {
                        throw new ArgumentNullException();
                    }

                    if (listRs.ListOfObjects == null)
                    {
                        return(new ListResult <CategoryViewModel>());
                    }

                    return(listRs);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #8
0
 public UserAuthentication()
 {
     this.entities = new LibraryManagementEntities();
 }
 public CategoryManagement()
 {
     this.entities = new LibraryManagementEntities();
 }
Пример #10
0
 public UserRegister()
 {
     this.entities = new LibraryManagementEntities();
 }
 public ReservationManagement()
 {
     this.entities = new LibraryManagementEntities();
 }
        // When you delete specialized you have to delete (category, specialcategory, book, borrower)
        public bool Delete(int id)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // Check first get item
                    var specialzed = libraryDb.Specializeds.FirstOrDefault(s => s.Id == id);
                    if (specialzed == null)
                    {
                        throw new ArgumentNullException("No exist");
                    }
                    //// Check if have child
                    //// 1. Get category
                    //var listCategory = (from a in libraryDb.Categories
                    //                   where a.Id == model.Id
                    //                   select a).ToList();

                    //// 2. Get special category
                    //var listSpecialCategory = (from a in libraryDb.SpecialCategories
                    //                           where a.Id == model.Id
                    //                           select a).ToList();

                    //// 3. Get book by category
                    //List<Book> lstBook = new List<Book>();
                    //foreach (var item in listCategory)
                    //{
                    //    var book = (from a in libraryDb.Books
                    //                where a.CategoryId == item.Id
                    //                select a).FirstOrDefault();

                    //    if (book != null)
                    //        lstBook.Add(book);
                    //}
                    //foreach (var item in listSpecialCategory)
                    //{
                    //    var book = (from a in libraryDb.Books
                    //                where a.SpecialCategoryId == item.Id
                    //                select a).FirstOrDefault();

                    //    if (book != null)
                    //        lstBook.Add(book);
                    //}
                    //// 4. Get borrower
                    //List<Borrower> lstBorrower = new List<Borrower>();
                    //foreach (var item in lstBook)
                    //{
                    //    var borrower = (from a in libraryDb.Borrowers
                    //                where a.BookId == item.Id
                    //                select a).FirstOrDefault();

                    //    if (borrower != null)
                    //        lstBorrower.Add(borrower);
                    //}

                    //// Delete Borrowers => Delete books => Delete Category => Delete SpecialCategory => Delete Specialized

                    //libraryDb.Borrowers.RemoveRange(lstBorrower);
                    //libraryDb.Books.RemoveRange(lstBook);
                    //libraryDb.Categories.RemoveRange(listCategory);
                    //libraryDb.SpecialCategories.RemoveRange(listSpecialCategory);

                    libraryDb.Specializeds.Remove(specialzed);

                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #13
0
        //public ListResult<UserBindingModel> GetList(string name = "", int? positionId = null, int? unitId = null, int? roleId = null, int? pageNumber = 0, int? pageSize = 0)
        //{
        //    try
        //    {
        //        using (var libraryDb = new LibraryManagementEntities())
        //        {
        //            var qry = from a in libraryDb.Users
        //                      select a;

        //            if (!string.IsNullOrWhiteSpace(name))
        //                qry = from a in qry
        //                      where a.Name.Contains(name)
        //                      select a;

        //            if (positionId != null)
        //                qry = from a in qry
        //                      where a.PositionId == positionId
        //                      select a;

        //            if (unitId != null)
        //                qry = from a in qry
        //                      where a.UnitId == unitId
        //                      select a;

        //            if (roleId != null)
        //                qry = from a in qry
        //                      where a.RoleId == roleId
        //                      select a;

        //            var listRs = ListResult<User>.GetDataPage(qry.OrderBy(x=>x.Name), pageNumber, pageSize);
        //            if (listRs == null) throw new ArgumentNullException();

        //            if (listRs.ListOfObjects == null) return new ListResult<UserBindingModel>();

        //            var listResult = new ListResult<UserBindingModel>();
        //            listResult.ListOfObjects = new List<UserBindingModel>();
        //            listResult.TotalRecord = listRs.TotalRecord;

        //            foreach (var item in listRs.ListOfObjects)
        //            {
        //                var user = _entityMapper.Map<User, UserBindingModel>(item);
        //                listResult.ListOfObjects.Add(user);
        //            }
        //            return listResult;
        //        }
        //    }
        //    catch (Exception)
        //    {
        //        throw;
        //    }
        //}

        public UserBindingViewModel getUser(string account, string password)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    var qry = from a in libraryDb.Users
                              join b in libraryDb.Positions on a.PositionId equals b.Id
                              join c in libraryDb.Units on a.UnitId equals c.Id
                              join d in libraryDb.Roles on a.RoleId equals d.Id
                              where a.Account == account && a.Password == password
                              select new
                    {
                        Id          = a.Id,
                        Account     = a.Account,
                        Password    = a.Password,
                        Name        = a.Name,
                        Gender      = a.Gender,
                        DayOfBirth  = a.DayOfBirth,
                        Address     = a.Address,
                        PhoneNumber = a.PhoneNumber,
                        PositionId  = a.PositionId,
                        Position    = b.Name,
                        UnitId      = a.UnitId,
                        Unit        = c.Name,
                        RoleId      = a.RoleId,
                        Role        = d.Name,
                        Email       = a.Email
                    };

                    List <UserBindingViewModel> LR = new List <UserBindingViewModel>();
                    foreach (var item in qry.ToList())
                    {
                        LR.Add(new UserBindingViewModel()
                        {
                            Id          = item.Id,
                            Account     = item.Account,
                            Password    = item.Password,
                            Name        = item.Name,
                            Gender      = item.Gender,
                            DayOfBirth  = item.DayOfBirth,
                            Address     = item.Address,
                            PhoneNumber = item.PhoneNumber,
                            PositionId  = item.PositionId,
                            Position    = item.Position,
                            UnitId      = item.UnitId,
                            Unit        = item.Unit,
                            RoleId      = item.RoleId,
                            Role        = item.Role,
                            Email       = item.Email
                        });
                    }

                    return(LR.FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public BaseRepository()
 {
     db    = new LibraryManagementEntities();
     table = db.Set <T>();
 }
Пример #15
0
 public BaseManager()
 {
     this._dbLibraryManagement = new LibraryManagementEntities();
 }
Пример #16
0
 public BaseManager(LibraryManagementEntities dbLibraryManagement)
 {
     this._dbLibraryManagement = dbLibraryManagement;
 }
Пример #17
0
        public ListResult <BookBindingViewModel> GetList(string searching, int?categoryId, int?specialCategoryId, int?bookShelfId, int?phblisherId,
                                                         int?authorId, int?pageNumber = 0, int?pageSize = 0)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    var qry = from a in libraryDb.Books
                              join b in libraryDb.Categories on a.CategoryId equals b.Id
                              join c in libraryDb.SpecialCategories on a.SpecialCategoryId equals c.Id
                              join d in libraryDb.BookShelves on a.BookShelfId equals d.Id
                              join e in libraryDb.Publishers on a.PublisherId equals e.Id
                              join f in libraryDb.Authors on a.AuthorId equals f.Id
                              select new {
                        Id                = a.Id,
                        Name              = a.Name,
                        Language          = a.Language,
                        ReleaseYear       = a.ReleaseYear,
                        PageCount         = a.PageCount,
                        Price             = a.Price,
                        Note              = a.Note,
                        Status            = a.Status,
                        AuthorId          = a.AuthorId,
                        Author            = f.Name,
                        PublisherId       = a.PublisherId,
                        Publisher         = e.Name,
                        CategoryId        = a.CategoryId,
                        Category          = b.Name,
                        SpecialCategoryId = a.SpecialCategoryId,
                        SpecialCategory   = c.Name,
                        BookShelfId       = a.BookShelfId,
                        BookShelf         = d.Name
                    };


                    if (!string.IsNullOrWhiteSpace(searching))
                    {
                        qry = from a in qry
                              where a.Name.Contains(searching) || a.Id.Contains(searching) || a.Status.Contains(searching)
                              select a;
                    }

                    if (categoryId != null && categoryId >= 1)
                    {
                        qry = from a in qry
                              where a.CategoryId == categoryId
                              select a;
                    }

                    if (specialCategoryId != null && specialCategoryId >= 1)
                    {
                        qry = from a in qry
                              where a.SpecialCategoryId == specialCategoryId
                              select a;
                    }

                    if (bookShelfId != null && bookShelfId >= 1)
                    {
                        qry = from a in qry
                              where a.BookShelfId == bookShelfId
                              select a;
                    }

                    if (phblisherId != null && phblisherId >= 1)
                    {
                        qry = from a in qry
                              where a.PublisherId == phblisherId
                              select a;
                    }

                    if (authorId != null && authorId >= 1)
                    {
                        qry = from a in qry
                              where a.AuthorId == authorId
                              select a;
                    }

                    List <BookBindingViewModel> LR = new List <BookBindingViewModel>();
                    foreach (var item in qry.ToList())
                    {
                        LR.Add(new BookBindingViewModel()
                        {
                            Id                = item.Id,
                            Name              = item.Name,
                            Author            = item.Author,
                            AuthorId          = item.AuthorId,
                            BookShelf         = item.BookShelf,
                            BookShelfId       = item.BookShelfId,
                            Category          = item.Category,
                            CategoryId        = item.CategoryId,
                            Language          = item.Language,
                            Note              = item.Note,
                            PageCount         = item.PageCount,
                            Price             = item.Price,
                            Publisher         = item.Publisher,
                            PublisherId       = item.PublisherId,
                            ReleaseYear       = item.ReleaseYear,
                            SpecialCategory   = item.SpecialCategory,
                            SpecialCategoryId = item.SpecialCategoryId,
                            Status            = item.Status
                        });
                    }



                    var listRs = ListResult <BookBindingViewModel> .GetDataPage(LR.OrderBy(x => x.Name), pageNumber, pageSize);

                    if (listRs == null)
                    {
                        throw new ArgumentNullException();
                    }

                    if (listRs.ListOfObjects == null)
                    {
                        return(new ListResult <BookBindingViewModel>());
                    }

                    return(listRs);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #18
0
 public UserManagement()
 {
     this.entities = new LibraryManagementEntities();
 }
Пример #19
0
 public LanguageManagement()
 {
     this.entities = new LibraryManagementEntities();
 }
Пример #20
0
        public ListResult <ReaderBindingViewModel> GetList(string name = "", string gender = "", string phoneNumber = "", int?positionId = null, int?unitId = null, int?pageNumber = 0, int?pageSize = 0)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    var qry = from a in libraryDb.Readers
                              join b in libraryDb.Positions on a.PositionId equals b.Id
                              join c in libraryDb.Units on a.UnitId equals c.Id
                              select new {
                        Id          = a.Id,
                        Name        = a.Name,
                        Gender      = a.Gender,
                        DayOfBirth  = a.DayOfBirth,
                        Address     = a.Address,
                        PhoneNumber = a.PhoneNumber,
                        Email       = a.Email,
                        Position    = b.Name,
                        Unit        = c.Name,
                        Note        = a.Note,
                        PositionId  = a.PositionId,
                        UnitId      = a.UnitId
                    };

                    if (!string.IsNullOrWhiteSpace(name))
                    {
                        qry = from a in qry
                              where a.Name.Contains(name)
                              select a;
                    }

                    if (!string.IsNullOrWhiteSpace(gender))
                    {
                        qry = from a in qry
                              where a.Gender.Contains(gender)
                              select a;
                    }

                    if (!string.IsNullOrWhiteSpace(phoneNumber))
                    {
                        qry = from a in qry
                              where a.PhoneNumber.Contains(phoneNumber)
                              select a;
                    }

                    if (positionId != null && positionId >= 1)
                    {
                        qry = from a in qry
                              where a.PositionId == positionId
                              select a;
                    }

                    if (unitId != null && unitId >= 1)
                    {
                        qry = from a in qry
                              where a.UnitId == unitId
                              select a;
                    }


                    List <ReaderBindingViewModel> LR = new List <ReaderBindingViewModel>();
                    foreach (var item in qry.ToList())
                    {
                        LR.Add(new ReaderBindingViewModel()
                        {
                            Id          = item.Id,
                            Name        = item.Name,
                            Address     = item.Address,
                            DayOfBirth  = item.DayOfBirth,
                            Email       = item.Email,
                            Gender      = item.Gender,
                            Note        = item.Note,
                            PhoneNumber = item.PhoneNumber,
                            Position    = item.Position,
                            PositionId  = item.PositionId,
                            Unit        = item.Unit,
                            UnitId      = item.UnitId
                        });
                    }



                    var listRs = ListResult <ReaderBindingViewModel> .GetDataPage(LR.OrderBy(x => x.Name), pageNumber, pageSize);

                    if (listRs == null)
                    {
                        throw new ArgumentNullException();
                    }

                    if (listRs.ListOfObjects == null)
                    {
                        return(new ListResult <ReaderBindingViewModel>());
                    }

                    return(listRs);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #21
0
        //public ListResult<BorrowerBindingModel> GetList(int? readerId, string bookId, DateTime? borrowDate, DateTime? payDate, string note,
        //      int? pageNumber = 0, int? pageSize = 0)
        //{
        //    try
        //    {
        //        using (var libraryDb = new LibraryManagementEntities())
        //        {
        //            var qry = from a in libraryDb.Borrowers
        //                      select a;

        //            if (!string.IsNullOrWhiteSpace(note))
        //                qry = from a in qry
        //                      where a.Note.Contains(note)
        //                      select a;

        //            if (readerId != null && readerId >= 1)
        //                qry = from a in qry
        //                      where a.ReaderId == readerId
        //                      select a;

        //            if (!string.IsNullOrWhiteSpace(bookId))
        //                qry = from a in qry
        //                      where a.BookId.Contains(bookId)
        //                      select a;

        //            if (borrowDate != null)
        //                qry = from a in qry
        //                      where a.BorrowDate >= borrowDate
        //                      select a;

        //            if (payDate != null)
        //                qry = from a in qry
        //                      where a.PayDate <= payDate
        //                      select a;

        //            var listRs = ListResult<Borrower>.GetDataPage(qry.OrderByDescending(x=>x.PayDate), pageNumber, pageSize);
        //            if (listRs == null) throw new ArgumentNullException();

        //            if (listRs.ListOfObjects == null) return new ListResult<BorrowerBindingModel>();

        //            var listResult = new ListResult<BorrowerBindingModel>();
        //            listResult.ListOfObjects = new List<BorrowerBindingModel>();
        //            listResult.TotalRecord = listRs.TotalRecord;

        //            foreach (var item in listRs.ListOfObjects)
        //            {
        //                var borrower = _entityMapper.Map<Borrower, BorrowerBindingModel>(item);
        //                listResult.ListOfObjects.Add(borrower);
        //            }
        //            return listResult;
        //        }
        //    }
        //    catch (Exception)
        //    {
        //        throw;
        //    }
        //}



        public ListResult <BorrowerBindingViewModel> GetList(string searching = "",
                                                             int?positionId   = null, int?unitId = null, int?pageNumber = 0, int?pageSize = 0)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    var qry = from a in libraryDb.Borrowers
                              join b in libraryDb.Books on a.BookId equals b.Id
                              join c in libraryDb.Readers on a.ReaderId equals c.Id
                              join d in libraryDb.Positions on c.PositionId equals d.Id
                              join g in libraryDb.Units on c.UnitId equals g.Id
                              where b.Status.Equals(SystemConstants.Borrowed)
                              select new {
                        ReaderId   = c.Id,
                        ReaderName = c.Name,
                        BookId     = b.Id,
                        BookName   = b.Name,
                        BorrowDate = a.BorrowDate,
                        Note       = a.Note,
                        CreatedBy  = a.CreatedBy,
                        Unit       = g.Name,
                        UnitId     = g.Id,
                        Position   = d.Name,
                        PositionId = d.Id
                    };

                    if (!string.IsNullOrWhiteSpace(searching))
                    {
                        qry = from a in qry
                              where a.ReaderName.Contains(searching) || a.BookId.Contains(searching) ||
                              a.BookName.Contains(searching) || a.Note.Contains(searching)
                              select a;
                    }



                    if (positionId != null && positionId >= 1)
                    {
                        qry = from a in qry
                              where a.PositionId == positionId
                              select a;
                    }

                    if (unitId != null && unitId >= 1)
                    {
                        qry = from a in qry
                              where a.UnitId == unitId
                              select a;
                    }



                    List <BorrowerBindingViewModel> LR = new List <BorrowerBindingViewModel>();
                    foreach (var item in qry.ToList())
                    {
                        LR.Add(new BorrowerBindingViewModel()
                        {
                            BookId     = item.BookId,
                            BookName   = item.BookName,
                            ReaderId   = item.ReaderId,
                            ReaderName = item.ReaderName,
                            BorrowDate = item.BorrowDate,
                            PositionId = item.PositionId,
                            Position   = item.Position,
                            UnitId     = item.UnitId,
                            Unit       = item.Unit,
                            Note       = item.Note,
                            CreatedBy  = item.CreatedBy
                        });
                    }

                    var listRs = ListResult <BorrowerBindingViewModel> .GetDataPage(LR.OrderBy(x => x.ReaderName), pageNumber, pageSize);

                    if (listRs == null)
                    {
                        throw new ArgumentNullException();
                    }

                    if (listRs.ListOfObjects == null)
                    {
                        return(new ListResult <BorrowerBindingViewModel>());
                    }

                    return(listRs);
                }
            }
            catch (Exception ex)
            {
                return(new ListResult <BorrowerBindingViewModel>());
            }
        }