Exemple #1
0
        public IHttpActionResult Get([FromUri] int id)
        {
            try
            {
                //throw new ArgumentNullException("this is a test");
                Reader reader;
                var    readerRepository = new ReaderRepository();

                if (id > 0)
                {
                    var readers = readerRepository.Retrieve();
                    reader = readers.FirstOrDefault(p => p.ReaderId == id);
                    if (reader == null)
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    reader = readerRepository.Create();
                }

                return(Ok(reader));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #2
0
        //POST: api/Products
        public IHttpActionResult Post([FromBody] Reader reader)
        {
            try
            {
                if (reader == null)
                {
                    return(BadRequest("Reader cannot be null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var readerRepository = new ReaderRepository();
                var newReader        = readerRepository.Save(reader);

                if (newReader == null)
                {
                    return(Conflict());
                }

                var requestUri  = Request.RequestUri;
                var newReaderId = newReader.ReaderId.ToString();
                var location    = requestUri + newReaderId;

                return(Created <Reader>(location, newReader));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #3
0
        //PUT: api/Books/5
        public IHttpActionResult Put([FromUri] int id, [FromBody] Reader reader)
        {
            try
            {
                if (reader == null)
                {
                    return(BadRequest("Reader cannot be null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var readerRepository = new ReaderRepository();
                var updateReader     = readerRepository.Save(id, reader);

                if (updateReader == null)
                {
                    return(NotFound());
                }

                return(StatusCode(HttpStatusCode.NoContent));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public ActionResult Delete(int id)
        {
            ReaderRepository repository = new ReaderRepository(AppConfig.ConnectionString);
            Reader           reader     = repository.GetById(id);

            return(View(reader));
        }
 public BorrowService(BorrowRepository borrowRepository,
                      ReaderRepository readerRepository,
                      BookRepository bookRepository)
 {
     BorrowRepository = borrowRepository;
     ReaderRepository = readerRepository;
 }
 public void CanCount()
 {
     var query = new LogQuery();
     var repo = new ReaderRepository();
     var count = repo.Count(query);
     Assert.Greater(count, 0);
 }
        public ActionResult Index()
        {
            ReaderRepository rep     = new ReaderRepository(AppConfig.ConnectionString);
            List <Reader>    readers = rep.GetAll();

            return(View(readers));
        }
        public ActionResult Edit(BookStatus model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            bool IsReader                   = false;
            BookStatusRepository rep        = new BookStatusRepository(AppConfig.ConnectionString);
            ReaderRepository     repo       = new ReaderRepository(AppConfig.ConnectionString);
            List <Reader>        readers    = repo.GetAll();
            BookStatus           bookStatus = new BookStatus();

            for (int i = 0; i < readers.Count; i++)
            {
                if (readers[i].Id == model.ReaderId)
                {
                    IsReader = true;
                }
            }

            BookRepository repos   = new BookRepository(AppConfig.ConnectionString);
            bool           IsTitle = false;
            List <Book>    books   = repos.GetAll();

            for (int i = 0; i < books.Count; i++)
            {
                if (books[i].Title == model.Title)
                {
                    IsTitle = true;
                }
            }

            if (IsTitle == true && IsReader == true)
            {
                bookStatus.Id           = model.Id;
                bookStatus.Title        = model.Title;
                bookStatus.ReaderId     = model.ReaderId;
                bookStatus.BorrowDate   = model.BorrowDate;
                bookStatus.ReturnDate   = model.ReturnDate;
                bookStatus.ReturnedDate = model.ReturnedDate;
                rep.Save(bookStatus);
                return(RedirectToAction("Index"));
            }
            else if (IsTitle == true && IsReader == false)
            {
                ViewBag.error = "No Reader with that Id !!!";
                return(View());
            }
            else if (IsTitle == false && IsReader == true)
            {
                ViewBag.error = "No Book with that Title !!!";
                return(View());
            }
            else
            {
                ViewBag.error = "Wrong Title and ReaderId !!!";
                return(View());
            }
        }
 public ReaderRepositoryTest()
 {
     repositoryFactory = new T();
     readerRepository  = repositoryFactory.CreateReaderRepository();
     countItems        = readerRepository.GetItems().Count();
     reader1           = new Reader("John Doe", "Boston");
     reader2           = new Reader("Alex Pupkin", "London");
 }
Exemple #10
0
        public ActionResult Edit(int id)
        {
            ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString);
            Reader           R  = Rr.GetOne(id);
            ProfileModel     Pm = MapToDbModels.ReaderToProfile(R);

            return(View(Pm));
        }
 public void CanClearLog()
 {
     var reader = new ReaderRepository();
     var query = new LogQuery();
     writer.Clear();
     var count = reader.Count(query);
     Assert.AreEqual(0, count);
 }
 public UnitOfWork(ApplicationDbContext context)
 {
     _context     = context;
     UsersR       = new UserRepository(_context);
     ReaderR      = new ReaderRepository(_context);
     OrderR       = new OrderRepository(_context);
     OrderDetailR = new OrderDetailRepository(_context);
 }
 List <Reader> GetReaders()
 {
     using (MyAppContext appContext = new MyAppContext())
     {
         ReaderRepository readerRepository = new ReaderRepository(appContext);
         return((List <Reader>)readerRepository.GetAll());
     }
 }
Exemple #14
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context = context;
     Books    = new BookRepository(context);
     Levels   = new LevelRepository(context);
     Readers  = new ReaderRepository(context);
     Ratings  = new RatingRepository(context);
 }
 public OrderObjectRepository(ReaderRepository readerRepository, BookRepository bookRepository, 
     LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository)
 {
     this.readerRepository = readerRepository;
     this.bookRepository = bookRepository;
     this.libraryDepartmentRepository = libraryDepartmentRepository;
     this.librarianRepository = librarianRepository;
     orders = new List<Order>();
 }
Exemple #16
0
 public LibraryService()
 {
     this.readerRepository = new ReaderRepository();
     this.reviewRepository = new ReviewRepository();
     this.bookRepository   = new BookRepository();
     this.autorRepository  = new AutorRepository();
     this.genderRepository = new GenderRepository();
     this.loanRepository   = new LoanRepository();
 }
        public ReaderBooksViewModel GetReaderBooks(int bookId)
        {
            ReaderBooksViewModel viewModel = new ReaderBooksViewModel()
            {
                Reader = ReaderRepository.GetSingleReader(ReaderRepository.CurrentId),
                Books  = BorrowRepository.GetBooksForReader(ReaderRepository.CurrentId)
            };

            return(viewModel);
        }
        public void CanCountFiltered(string filter, string filterValue, int expected)
        {
            var query = new LogQuery() {
                Filter = filter,
                FilterValue = filterValue
            };

            var repo = new ReaderRepository();
            Assert.AreEqual(expected, repo.Count(query));
        }
        public JsonResult GetStates(string country)
        {
            JsonResult result = new JsonResult();

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            ReaderRepository repo = new ReaderRepository();

            result.Data = repo.GetStates(country);
            return(result);
        }
        public JsonResult GetCities(string state)
        {
            JsonResult result = new JsonResult();

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            ReaderRepository repo = new ReaderRepository();

            result.Data = repo.GetCity(state);
            return(result);
        }
        public void changeButton_Click(object sender, EventArgs e)
        {
            if (!(dataGridView1.SelectedRows.Count > 0))
            {
                return;
            }
            AddReaderForm    addReaderForm    = new AddReaderForm();
            ReaderRepository readerRepository = new ReaderRepository();

            int  index     = dataGridView1.SelectedRows[0].Index;
            int  id        = 0;
            bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);

            if (converted == false)
            {
                return;
            }

            Reader reader = readerRepository.FindById(id);

            addReaderForm.nameTextBox.Text       = reader.Name;
            addReaderForm.surnameTextBox.Text    = reader.Surname;
            addReaderForm.patronymicTextBox.Text = reader.Patronymic;
            addReaderForm.dateTimePicker.Value   = reader.DateOfBirth;
            addReaderForm.emailTextBox.Text      = reader.Email;
            addReaderForm.telNumberTextBox.Text  = reader.TelephoneNumber;

            DialogResult dialogResult = addReaderForm.ShowDialog(this);

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }

            string   name       = addReaderForm.nameTextBox.Text;
            string   surname    = addReaderForm.surnameTextBox.Text;
            string   patronymic = addReaderForm.patronymicTextBox.Text;
            DateTime DoB        = addReaderForm.dateTimePicker.Value;
            string   email      = addReaderForm.emailTextBox.Text;
            string   telNumber  = addReaderForm.telNumberTextBox.Text;


            reader.Name            = name;
            reader.Surname         = surname;
            reader.Patronymic      = patronymic;
            reader.DateOfBirth     = DoB;
            reader.Email           = email;
            reader.TelephoneNumber = telNumber;


            readerRepository.Update(reader);

            _db.SaveChanges();
            SetDataGridView();
        }
        public JsonResult UpdateLike(string informationId)
        {
            JsonResult result = new JsonResult();

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            ReaderRepository repo = new ReaderRepository();
            var listitem          = repo.UpdateLike(informationId);

            result.Data = listitem;
            return(result);
        }
        public OrderMSSQLRepository(ReaderRepository readerRepository, BookRepository bookRepository, 
            LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository,
            LibraryDataContext context)
        {
            this.readerRepository = readerRepository;
            this.bookRepository = bookRepository;
            this.libraryDepartmentRepository = libraryDepartmentRepository;
            this.librarianRepository = librarianRepository;

            this.context = context;
        }
        public OrderTextRepository(ReaderRepository readerRepository, BookRepository bookRepository, 
            LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository)
        {
            this.readerRepository = readerRepository;
            this.bookRepository = bookRepository;
            this.libraryDepartmentRepository = libraryDepartmentRepository;
            this.librarianRepository = librarianRepository;

            if (!Directory.GetParent(FileName).Exists) Directory.GetParent(FileName).Create();
            if (!File.Exists(FileName)) File.Create(FileName).Close();
        }
Exemple #25
0
        public ActionResult Index()
        {
            ReaderRepository repository = new ReaderRepository();
            List <Reader>    readers    = repository.GetAll();

            ReaderListViewModel model = new ReaderListViewModel();

            model.Readers = readers;

            return(View(model));
        }
Exemple #26
0
        public ActionResult Delete(ReaderDeleteViewModel model)
        {
            ReaderRepository repository = new ReaderRepository();

            if (model.Id.ToString() != String.Empty)
            {
                repository.Delete(model.Id);
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(Reader model)
        {
            ReaderRepository repository = new ReaderRepository(AppConfig.ConnectionString);

            if (model.Id.ToString() != String.Empty)
            {
                repository.Delete(model.Id);
            }


            return(RedirectToAction("Index"));
        }
Exemple #28
0
        public OrderRepositoryTest()
        {
            repositoryFactory           = new T();
            readerRepository            = repositoryFactory.CreateReaderRepository();
            libraryDepartmentRepository = repositoryFactory.CreateLibraryDepartmentRepository();
            bookRepository      = repositoryFactory.CreateBookRepository(libraryDepartmentRepository);
            librarianRepository = repositoryFactory.CreateLibrarianRepository(libraryDepartmentRepository);

            orderRepository = repositoryFactory.CreateOrderRepository(readerRepository, bookRepository, libraryDepartmentRepository, librarianRepository);

            countItems = orderRepository.GetItems().Count();
        }
Exemple #29
0
        public ViewResult Register(RegisterModel Rm, HttpPostedFileBase ProfilePicture)
        {
            List <string> matchContentType = new List <string>()
            {
                "image/jpeg", "image/png", "image/gif"
            };

            if (!matchContentType.Contains(ProfilePicture.ContentType) || ProfilePicture.ContentLength > 80000)
            {
                ViewBag.ErrorMessage = "You can upload a file with the following exctentions(png, jpg, gif)";
                return(View());
            }
            if (!ModelState.IsValid)
            {
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        ViewBag.ErrorMessage += error.ErrorMessage + "<br>";
                    }
                }
            }
            else
            {
                // insert the new reader
                ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString);
                Reader           R  = Rr.Insert(MapToDbModels.RegisterToReader(Rm));
                if (R != null)
                {
                    //saving the picture
                    string[] splitFileName  = ProfilePicture.FileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                    string   ext            = splitFileName[splitFileName.Length - 1];
                    string   newFileName    = R.Id + "." + ext;
                    string   folderpath     = Server.MapPath("~/Photos/");
                    string   FileNameToSave = folderpath + "/" + newFileName;

                    try
                    {
                        ProfilePicture.SaveAs(FileNameToSave);
                    }
                    catch (Exception)
                    {
                        ViewBag.ErrorMessage = "The image couldn't be saved";
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "Error during Insertion";
                }
            }
            return(View("Login"));
        }
Exemple #30
0
 public IHttpActionResult Get()
 {
     try
     {
         var readerRepository = new ReaderRepository();
         var readers          = readerRepository.Retrieve().AsQueryable();
         return(Ok(readers));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Exemple #31
0
        public ActionResult Edit(EditProfile Ep)
        {
            ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString);
            Reader           R  = MapToDbModels.EditReader(Ep);

            if (Rr.Update(R))
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
        // GET: Reader
        public ActionResult Index()
        {
            ReaderRepository   repo    = new ReaderRepository();
            CategoryRepository catRepo = new CategoryRepository();
            ReaderViewModel    model   = new ReaderViewModel();

            model.CountryOptions     = repo.GetCountry();
            model.StateOptions       = defaultListItem;
            model.CityOptions        = defaultListItem;
            model.CategoryOptions    = catRepo.GetCategory();
            model.SubCategoryOptions = catRepo.GetSubCategory();

            return(View(model));
        }
        public ActionResult Index(ReaderViewModel model)
        {
            var repoReader             = new ReaderRepository();
            CategoryRepository catRepo = new CategoryRepository();

            model.CountryOptions     = repoReader.GetCountry();
            model.StateOptions       = (!string.IsNullOrWhiteSpace(model.Country)) ? repoReader.GetStates(model.Country) : defaultListItem;
            model.CityOptions        = (!string.IsNullOrWhiteSpace(model.State)) ? repoReader.GetCity(model.State) : defaultListItem;
            model.CategoryOptions    = catRepo.GetCategory();
            model.SubCategoryOptions = defaultListItem;
            model.information        = repoReader.GetRecords(model);

            return(View(model));
        }
Exemple #34
0
        public ActionResult Delete(int id)
        {
            ReaderRepository repository = new ReaderRepository();

            Reader reader = repository.GetById(id);

            ReaderDeleteViewModel model = new ReaderDeleteViewModel();

            model.firstName  = reader.firstName;
            model.lastName   = reader.lastName;
            model.readerCard = reader.readerCard;
            model.expireDate = reader.expireDate;

            return(View(model));
        }
Exemple #35
0
        public CrudContext()
        {
            InsertPraseHolderRepository insertPrase      = new InsertPraseHolderRepository();
            ReaderRepository            readerRepository = new ReaderRepository();

            sqlDictonnary
                = new Dictionary <CrudEnum, DBProperty>()
                {
                { CrudEnum.GetLogin, new DBProperty()
                  {
                      Query          = "SELECT * FROM ServiceUser WHERE UserName = @UserName AND Password = @Password",
                      SetPlaseHolder = insertPrase.InsertServerUserHolder,
                      Boolanswer     = readerRepository.IsExist
                  } },
                };
        }
Exemple #36
0
        private void SetDataGridView()
        {
            var readerRepository = new ReaderRepository();

            readerDataGridView.DataSource = readerRepository.Get()
                                            .OrderBy(b => b.Id)
                                            .Select(b => new
            {
                b.Id,
                b.Name,
                b.Surname,
                b.Patronymic,
                b.DateOfBirth,
                b.TelephoneNumber,
                b.Email
            }).ToList();
        }
        public OrderXMLRepository(ReaderRepository readerRepository, BookRepository BookRepository, 
            LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository)
        {
            this.readerRepository = readerRepository;
            this.bookRepository = BookRepository;
            this.libraryDepartmentRepository = libraryDepartmentRepository;
            this.librarianRepository = librarianRepository;

            if (!Directory.GetParent(FileName).Exists) Directory.GetParent(FileName).Create();
            if (File.Exists(FileName))
            {
                document = XDocument.Load(FileName);
            }
            else
            {
                document = new XDocument(
                    new XDeclaration("1.0", "utf-8", "yes"),
                    new XElement("Orders", null));
                document.Save(FileName);
            }
        }
 public OrderRepository CreateOrderRepository(ReaderRepository readerRepository, BookRepository bookRepository, 
     LibraryDepartmentRepository libraryDepartmentRepository, LibrarianRepository librarianRepository)
 {
     return new OrderTextRepository(readerRepository, bookRepository, libraryDepartmentRepository, librarianRepository);
 }