コード例 #1
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();
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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;
 }
コード例 #5
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;
 }
コード例 #6
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);
        }
コード例 #7
0
        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
            };
        }
コード例 #8
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;
        }
コード例 #9
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");
     }
 }
コード例 #10
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>();
        }
コード例 #11
0
 public void CreateReader(ReaderBusinessModel reader)
 {
     var mapper = new ReaderMapper();
     this.uow.Readers.Add(mapper.Map(reader));
     this.uow.Commit();
 }
コード例 #12
0
 public void UpdateReader(ReaderBusinessModel reader)
 {
     this.readerManager.UpdateReader(reader);
 }
コード例 #13
0
        public void ReaderModelToEntityMappingIsNullTest()
        {
            _readerBusinessModel = null;
            var result = _readerMapper.Map(_readerBusinessModel);

            Assert.IsNull(result);
        }
コード例 #14
0
 public void CreateReader(ReaderBusinessModel reader)
 {
     throw new NotImplementedException();
 }
コード例 #15
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);
            }
        }
コード例 #16
0
 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()));
         }
     }
 }
コード例 #17
0
 public void RecalculateReaderTagScoresAsync(ReaderBusinessModel reader)
 {
     Task t = new Task(() => this.RecalculateReaderTagScores(reader));
     t.Start();
 }
コード例 #18
0
 private bool IsExisting(ReaderBusinessModel reader)
 {
     return
         this.GetAllReaders()
             .Any(
                 r =>
                 r.FirstName == reader.FirstName && r.LastName == reader.LastName
                 && r.Birthday == reader.Birthday);
 }
コード例 #19
0
 public void CreateReader(ReaderBusinessModel reader)
 {
     if (!this.IsExisting(reader))
     {
         this.readerFacade.CreateReader(reader);
     }
 }