Beispiel #1
0
 public void CreateReader(ReaderBusinessModel reader)
 {
     if (!this.IsExisting(reader))
     {
         this.readerFacade.CreateReader(reader);
     }
 }
Beispiel #2
0
        public void UpdateReader(ReaderBusinessModel reader)
        {
            List <Tag> preferences = new List <Tag>();

            if (reader.Preferences != null)
            {
                foreach (var tag in reader.Preferences)
                {
                    preferences.Add(this.uow.Tags.GetById(tag.id));
                }
            }

            Reader currentReader = uow.Readers.GetById(reader.ReaderId);

            if (reader.UserProfileBusiness != null)
            {
                UserProfile user = this.uow.UsersProfiles.GetById(reader.UserProfileBusiness.UserId);
                currentReader.UserProfile = user;
            }
            currentReader.Address     = reader.Address;
            currentReader.Birthday    = reader.Birthday;
            currentReader.EMail       = reader.EMail;
            currentReader.FirstName   = reader.FirstName;
            currentReader.LastName    = reader.LastName;
            currentReader.Phone       = reader.Phone;
            currentReader.Preferences = preferences;
            uow.Readers.Update(currentReader);
            uow.Commit();
        }
Beispiel #3
0
        public void CreateReader(ReaderBusinessModel reader)
        {
            var mapper = new ReaderMapper();

            this.uow.Readers.Add(mapper.Map(reader));
            this.uow.Commit();
        }
Beispiel #4
0
        public ScannedPageFacadeTest()
        {
            _scannedPageMapper = new ScannedPageMapper();

            _fixture = new Fixture();
            _fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            _fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            _fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book)));
            _fixture.Customizations.Add(new TypeRelay(typeof(ItemBusinessModel), typeof(BookBusinessModel)));

            _scannedPage = _fixture.Create <ScannedPage>();
            _scannedPageBusinessModel = _fixture.Create <ScannedPageBusinessModel>();

            _readerBusinessModel = _fixture.Create <ReaderBusinessModel>();
            ReaderMapper readerMapper = new ReaderMapper();

            _reader = readerMapper.Map(_readerBusinessModel);

            _itemBusinessModel = _fixture.Create <ItemBusinessModel>();
            ItemMapper itemMapper = new ItemMapper();

            _item = itemMapper.Map(_itemBusinessModel);

            this.uow = Initializer.GetLibraryUow();
            uow.ScannedPages.Add(this._scannedPage);
            uow.Readers.Add(this._reader);
            uow.Items.Add(this._item);
            this._scannedPageFacade = new ScannedPageFacade(uow);
        }
Beispiel #5
0
        public SearchItemFacadeTest()
        {
            _itemMapper = new ItemMapper();

            _fixture = new Fixture();
            _fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            _fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            _fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book)));
            _fixture.Customizations.Add(new TypeRelay(typeof(ItemBusinessModel), typeof(BookBusinessModel)));

            _readerBusinessModel = _fixture.Create <ReaderBusinessModel>();
            ReaderMapper readerMapper = new ReaderMapper();

            _reader = readerMapper.Map(_readerBusinessModel);

            _item = _fixture.Create <Item>();
            _itemBusinessModel = _itemMapper.Map(_item);

            _tag = _fixture.Create <Tag>();

            this.uow = Initializer.GetLibraryUow();

            uow.Readers.Add(this._reader);
            uow.Items.Add(this._item);
            uow.Tags.Add(_tag);
            this._searchItemFacade = new SearchItemFacade(uow);
        }
Beispiel #6
0
        public void ReaderModelToEntityMappingIsNullTest()
        {
            _readerBusinessModel = null;
            var result = _readerMapper.Map(_readerBusinessModel);

            Assert.IsNull(result);
        }
Beispiel #7
0
        public DeptorsReadersModel Map(ReaderHistory o)
        {
            if (o == null)
            {
                return(null);
            }
            DeptorsReadersModel    deptorsReadersBusiness = new DeptorsReadersModel();
            ReaderMapper           readerMapper           = new ReaderMapper();
            InventoryMapper        inventoryMapper        = new InventoryMapper();
            ReaderBusinessModel    readerBusinessModel    = readerMapper.Map(o.Reader);
            InventoryBusinessModel invertoryBusinessModel = inventoryMapper.Map(o.Inventory);

            deptorsReadersBusiness.readerId  = readerBusinessModel.ReaderId;
            deptorsReadersBusiness.FirstName = readerBusinessModel.FirstName;
            deptorsReadersBusiness.LastName  = readerBusinessModel.LastName;
            deptorsReadersBusiness.Address   = readerBusinessModel.Address;
            deptorsReadersBusiness.Phone     = readerBusinessModel.Phone;
            if (o.Inventory != null)
            {
                deptorsReadersBusiness.ItemName = invertoryBusinessModel.Item.Name;
            }
            deptorsReadersBusiness.StartDate  = o.StartDate;
            deptorsReadersBusiness.FinishDate = o.FinishDate;

            return(deptorsReadersBusiness);
        }
Beispiel #8
0
        public ReaderBusinessModel BindUserWithReader(int userId, int readerId)
        {
            ReaderBusinessModel      readerBusinessModel      = this.readerManager.GetReaderById(readerId);
            UserProfileBusinessModel userProfileBusinessModel = usersFacade.GetUserById(userId);

            readerBusinessModel.UserProfileBusiness = userProfileBusinessModel;
            return(readerBusinessModel);
        }
        public ReaderHistoryMapperTest()
        {
            this.readerHistoryMapper = new ReaderHistoryMapper();

            this.readerEntityToMap = new Reader {
                FirstName = "Bob", LastName = "Hopkins"
            };

            this.readerModelToMap = new ReaderBusinessModel {
                FirstName = "Bob", LastName = "Hopkins"
            };

            this.inventoryEntityToMap = new Inventory {
                Number = "0000000001-001"
            };

            this.inventoryModelToMap = new InventoryBusinessModel {
                Number = "0000000001-001"
            };

            this.readerHistoryEntityToMap = new ReaderHistory
            {
                ReaderHistoryId = 1,
                StartDate       = Convert.ToDateTime("2013.12.12"),
                ReturnDate      = Convert.ToDateTime("2013.12.20"),
                FinishDate      = Convert.ToDateTime("2013.12.28"),
                Reader          = this.readerEntityToMap,
                Inventory       = this.inventoryEntityToMap
            };

            this.readerHistoryEntityToCompareWith = new ReaderHistory
            {
                ReaderHistoryId = 1,
                StartDate       = Convert.ToDateTime("2013.12.12"),
                ReturnDate      = Convert.ToDateTime("2013.12.20"),
                FinishDate      = Convert.ToDateTime("2013.12.28"),
                Reader          = this.readerEntityToMap,
                Inventory       = this.inventoryEntityToMap
            };
            this.ReaderHistoryModelToMap = new ReaderHistoryBusinessModel
            {
                Id                = 1,
                StartDate         = Convert.ToDateTime("2013.12.12"),
                ReturnDate        = Convert.ToDateTime("2013.12.20"),
                FinishDate        = Convert.ToDateTime("2013.12.28"),
                ReaderBusiness    = this.readerModelToMap,
                InventoryBusiness = this.inventoryModelToMap
            };
            this.ReaderHistoryModelToCompareWith = new ReaderHistoryBusinessModel
            {
                Id                = 1,
                StartDate         = Convert.ToDateTime("2013.12.12"),
                ReturnDate        = Convert.ToDateTime("2013.12.20"),
                FinishDate        = Convert.ToDateTime("2013.12.28"),
                ReaderBusiness    = this.readerModelToMap,
                InventoryBusiness = this.inventoryModelToMap
            };
        }
Beispiel #10
0
 private bool IsExisting(ReaderBusinessModel reader)
 {
     return
         (this.GetAllReaders()
          .Any(
              r =>
              r.FirstName == reader.FirstName && r.LastName == reader.LastName &&
              r.Birthday == reader.Birthday));
 }
Beispiel #11
0
        public ReaderBusinessModel GetReaderByEmail(string email)
        {
            ReaderBusinessModel readerBusinessModel = new ReaderBusinessModel();
            Reader       reader       = this.uow.Readers.GetAll().FirstOrDefault(r => r.EMail == email);
            ReaderMapper readerMapper = new ReaderMapper();

            readerBusinessModel = readerMapper.Map(reader);
            return(readerBusinessModel);
        }
Beispiel #12
0
        public ReaderBusinessModel GetReaderByFullName(string firstName, string lastName)
        {
            ReaderBusinessModel readerBusiness = new ReaderBusinessModel();
            Reader reader =
                this.uow.Readers.GetAll().FirstOrDefault(r => (r.FirstName == firstName && r.LastName == lastName));
            ReaderMapper mapper = new ReaderMapper();

            readerBusiness = mapper.Map(reader);
            return(readerBusiness);
        }
Beispiel #13
0
        public HttpResponseMessage Create(ReaderBusinessModel reader)
        {
            if (ModelState.IsValid && reader != null)
            {
                this.readerManager.CreateReader(reader);
                return(Request.CreateResponse(HttpStatusCode.Created));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
Beispiel #14
0
        public HttpResponseMessage Update([FromBody] ReaderBusinessModel reader)
        {
            if (ModelState.IsValid)
            {
                this.readerManager.UpdateReader(reader);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
        public ActionResult EditReader(int id)
        {
            ReaderBusinessModel reader = this.readerManager.GetReaderById(id);

            if (reader == null)
            {
                return(this.HttpNotFound());
            }

            return(View(reader));
        }
        public UnconfirmedUsersForWidgetsModel(UsersConfirmationModel userConfirmationModel)
        {
            UserProfileBusinessModel user   = userConfirmationModel.UnconfirmedUser;
            ReaderBusinessModel      reader = userConfirmationModel.CoincidedReaderBusiness;

            this.UserName   = user != null ? user.UserName : "******";
            this.ReaderName = reader != null
                ? reader.FirstName + " " + reader.LastName
                : "Reader with such e-mail does not exist";
            this.RoleName = "Unregistered";
        }
 public ActionResult EditReader(ReaderBusinessModel reader)
 {
     try
     {
         this.readerManager.UpdateReader(reader);
         return(RedirectToAction("ReaderDetails", new { id = reader.ReaderId }));
     }
     catch
     {
         return(View());
     }
 }
        public ReaderBusinessModel Login(string login, string password)
        {
            ReaderBusinessModel reader = null;

            //WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName",
            //           autoCreateTables: true);

            if (WebSecurity.Login(login, password))
            {
                reader = this.readerManager.GetReaderByUserId(userManager.GetUserByUserName(login).UserId);
            }
            return(reader);
        }
        private void RecalculateReaderTagScores(ReaderBusinessModel reader)
        {
            var allItems = this.itemManager.GetAllItems();

            foreach (var item in allItems)
            {
                if (this.tagScoresFacade.GetScore(reader.ReaderId, item.Id) != -1)
                {
                    this.tagScoresFacade.UpdateOrCreateScore(reader.ReaderId,
                                                             item.Id,
                                                             this.CalculateScore(reader.Preferences, item.Tags.ToList()));
                }
            }
        }
Beispiel #20
0
        public ReadingFromExcelModel GetReadersFromFile(string fileName)
        {
            var result = new ReadingFromExcelModel();

            //reading from excel
            var        excel = new ExcelQueryFactory();
            List <Row> readers;

            try
            {
                excel.FileName = fileName;
                readers        = excel.Worksheet().ToList();
                if (readers.Count > 0)
                {
                    if (!readers[0].ColumnNames.Contains("FirstName") || !readers[0].ColumnNames.Contains("LastName") ||
                        !readers[0].ColumnNames.Contains("Address") || !readers[0].ColumnNames.Contains("Birthday") ||
                        !readers[0].ColumnNames.Contains("Email") || !readers[0].ColumnNames.Contains("Telephone"))
                    {
                        throw new Exception();
                    }
                }
            }
            catch
            {
                throw new ArgumentException("Invalid input file structure!");
            }

            for (int i = 0; i < readers.Count(); i++)
            {
                var validationResult = this.ValidateExcelRow(readers[i]);
                if (validationResult.MemberNames.Count() == 0)
                {
                    var readerBm = new ReaderBusinessModel();
                    readerBm.FirstName = readers[i]["FirstName"];
                    readerBm.LastName  = readers[i]["LastName"];
                    readerBm.Address   = readers[i]["Address"];
                    readerBm.Birthday  = readers[i]["Birthday"].Cast <DateTime>();
                    readerBm.EMail     = readers[i]["Email"];
                    readerBm.Phone     = readers[i]["Telephone"];
                    result.Readers.Add(readerBm);
                }
                else
                {
                    validationResult.ErrorMessage = string.Format("Line: {0}", i + 1);
                    result.Errors.Add(validationResult);
                }
            }

            return(result);
        }
Beispiel #21
0
        public void ConfirmUserWithReader(int userId, int readerId, string role)
        {
            UserProfileBusinessModel userProfileBusinessModel = usersFacade.SetRoleToUser(userId, role);

            usersFacade.UpdateUserProfile(userProfileBusinessModel);
            ReaderBusinessModel readerBusinessModel = BindUserWithReader(userId, readerId);

            this.readerManager.UpdateReader(readerBusinessModel);
            MailSender mailer = new MailSender();
            string     text   = "Congradulations! You are successfully registered in the SchoolLibrary. Your user name is " +
                                userProfileBusinessModel.UserName + ". You are confirmed to reader " +
                                readerBusinessModel.FirstName + " " + readerBusinessModel.LastName;

            mailer.Send(readerBusinessModel.EMail, "Confirmation", text);
        }
Beispiel #22
0
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     this.historyBusinessModelForGridListView.Items.Clear();
     titleLabel.Content = "";
     login    = loginTextBox.Text;
     password = passwordTextBox.Password;
     reader   = client.Login(login, password);
     if (reader != null)
     {
         readerProfileLabel.Content = "Welcome:  " + reader.FirstName + "  " + reader.LastName;
     }
     else
     {
         MessageBox.Show("Your login or password is wrong");
     }
 }
        public ActionResult CreateReader(ReaderBusinessModel reader)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    this.readerManager.CreateReader(reader);
                }

                return(RedirectToAction("Readers", "Librarian"));
            }
            catch
            {
                return(View());
            }
        }
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     this.historyBusinessModelForGridListView.Items.Clear();
     titleLabel.Content = "";
     login = loginTextBox.Text;
     password = passwordTextBox.Password;
     reader = client.Login(login, password);
     if (reader != null)
     {
         readerProfileLabel.Content = "Welcome:  " + reader.FirstName + "  " + reader.LastName;
     }
     else
     {
         MessageBox.Show("Your login or password is wrong");
     }
 }
Beispiel #25
0
 public ActionResult Confirm(string userName, string readerName, string role)
 {
     if (readerName != "Reader with such e-mail does not exist")
     {
         UserProfileBusinessModel user   = this.userManager.GetUserByUserName(userName);
         ReaderBusinessModel      reader = new ReaderBusinessModel();
         reader = this.readerManager.GetReaderByFullName(readerName);
         int userId   = user.UserId;
         int readerId = reader.ReaderId;
         this.userManager.ConfirmUserWithReader(userId, readerId, role);
         return(this.RedirectToAction("IndexWidgets"));
     }
     else
     {
         return(this.RedirectToAction("ShowUnconfirmedUsersWidget"));
     }
 }
Beispiel #26
0
        public void UpdateReader(ReaderBusinessModel reader)
        {
            var currentReader = this.GetReaderById(reader.ReaderId);

            if (reader.UserProfileBusiness != null && currentReader.EMail != reader.EMail)
            {
                using (var scope = new TransactionScope())
                {
                    this.readerFacade.UpdateReader(reader);
                    this.usersFacade.UpdateUsersEmail(reader.UserProfileBusiness.UserId, reader.EMail);

                    scope.Complete();
                }
            }
            else
            {
                this.readerFacade.UpdateReader(reader);
            }
        }
Beispiel #27
0
        public HistoryBusinessModelForGrid Map(ReaderHistory o)
        {
            if (o == null)
            {
                return(null);
            }
            HistoryBusinessModelForGrid readerHistoryBusiness = new HistoryBusinessModelForGrid();
            ReaderMapper           readerMapper           = new ReaderMapper();
            InventoryMapper        inventoryMapper        = new InventoryMapper();
            ReaderBusinessModel    readerBusinessModel    = readerMapper.Map(o.Reader);
            InventoryBusinessModel invertoryBusinessModel = inventoryMapper.Map(o.Inventory);

            readerHistoryBusiness.ReaderName = readerBusinessModel.FirstName;
            readerHistoryBusiness.ItemName   = invertoryBusinessModel.Item.Name;
            readerHistoryBusiness.StartDate  = o.StartDate;
            readerHistoryBusiness.FinishDate = o.FinishDate;

            return(readerHistoryBusiness);
        }
Beispiel #28
0
        public List <UsersConfirmationModel> CreateListOfUnconfirmedUsers(string[] allUnconfirmedUsers)
        {
            List <UsersConfirmationModel> list = new List <UsersConfirmationModel>();

            foreach (var item in allUnconfirmedUsers)
            {
                UserProfileBusinessModel user           = usersFacade.GetUserByUserName(item);
                ReaderBusinessModel      readerBusiness = readerManager.GetReaderByEmail(user.Email);
                UsersConfirmationModel   listItem       = new UsersConfirmationModel
                {
                    CoincidedReaderBusiness = readerBusiness,
                    UnconfirmedUser         = user
                };

                list.Add(listItem);
            }

            return(list);
        }
        //
        // GET: /Account/Manage

        public ActionResult Manage(ManageMessageId?message)
        {
            ReaderBusinessModel currentReader = this._readerManager.GetReaderByUserId(WebSecurity.CurrentUserId);

            if (currentReader == null)
            {
                ViewBag.CurrentReaderId = 0;
            }
            else
            {
                ViewBag.CurrentReaderId = currentReader.ReaderId;
            }

            ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
                : "";
            ViewBag.HasLocalPassword = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name));
            ViewBag.ReturnUrl        = Url.Action("Manage");
            return(View());
        }
        public ReaderHistoryBusinessModel Map(ReaderHistory o)
        {
            if (o == null)
            {
                return(null);
            }
            ReaderHistoryBusinessModel readerHistoryBusiness = new ReaderHistoryBusinessModel();
            ReaderMapper           readerMapper           = new ReaderMapper();
            InventoryMapper        inventoryMapper        = new InventoryMapper();
            ReaderBusinessModel    readerBusinessModel    = readerMapper.Map(o.Reader);
            InventoryBusinessModel invertoryBusinessModel = inventoryMapper.Map(o.Inventory);

            readerHistoryBusiness.Id                = o.ReaderHistoryId;
            readerHistoryBusiness.StartDate         = o.StartDate;
            readerHistoryBusiness.ReturnDate        = o.ReturnDate;
            readerHistoryBusiness.FinishDate        = o.FinishDate;
            readerHistoryBusiness.ReaderBusiness    = readerBusinessModel;
            readerHistoryBusiness.InventoryBusiness = invertoryBusinessModel;

            return(readerHistoryBusiness);
        }
Beispiel #31
0
        public ReaderMapperTest()
        {
            #region Old Initialization
            //_readerBusinessModel = new ReaderBusinessModel
            //{
            //    ReaderId = 1000,
            //    FirstName = "Mykola",
            //    LastName = "Stepanyak",
            //    Address = "Wall St. 123",
            //    Birthday = new DateTime(2012, 1, 1),
            //    Phone = "067-299-29-99",
            //    EMail = "*****@*****.**",
            //    Preferences = null
            //};

            //_reader = new Reader
            //{
            //    ReaderId = 2000,
            //    FirstName = "Mykola",
            //    LastName = "Stepanyak",
            //    Address = "Wall St. 123",
            //    Birthday = new DateTime(2012, 2, 2),
            //    Phone = "067-299-29-99",
            //    EMail = "*****@*****.**"
            //};
            #endregion

            _readerMapper = new ReaderMapper();

            Fixture fixture = new Fixture {
                RepeatCount = 1
            };
            fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book)));

            _reader = fixture.Create <Reader>();
            _readerBusinessModel = fixture.Create <ReaderBusinessModel>();
        }