public ActionResult Edit(AccessionRecord accessionRecord)
 {
     if (ModelState.IsValid)
     {
         service.Update(accessionRecord);
         return(RedirectToAction("Index"));
     }
     return(View(accessionRecord));
 }
        public AccessionRecord GetRandomIssuableAccRecord(int itemid)
        {
            IEnumerable <AccessionRecord> list = this.GetAllIssuableAccRecords();

            int             maxRecords  = list.Count() - 1;
            Random          rnd         = new Random();
            int             randomIndex = rnd.Next(0, maxRecords);
            AccessionRecord retval      = list.ElementAt(randomIndex);

            return(retval);
        }
        public void TestGetRandomIssuableAccRecord()
        {
            dynamic service = new IssuedItemService(mockContext.Object);

            // For this test, we set all issuedItems as "Returned"
            foreach (var i in issuedItems)
            {
                i.IsReturned = true;
            }
            AccessionRecord ar = service.GetRandomIssuableAccRecord(itemid: 1);

            Assert.AreEqual(1, ar.Item.ItemId);
        }
        // GET: AccessionRecords/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AccessionRecord accessionRecord = service.GetAccessionRecordById(id);

            if (accessionRecord == null)
            {
                return(HttpNotFound());
            }
            return(View(accessionRecord));
        }
        // GET: AccessionRecords/Create
        public ActionResult Create(int?itemid)
        {
            AccessionRecord newRecord = new AccessionRecord();

            if (itemid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Item item = service.GetItemService().GetItemById(itemid);

            newRecord.Item          = item;
            newRecord.DateOfReceipt = DateTime.Now.Date;
            return(View(newRecord));
        }
예제 #6
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AccessionRecord = await _context.AccessionRecord.FirstOrDefaultAsync(m => m.Id == id);

            if (AccessionRecord == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public void TestCreateWorks()
        {
            AccessionRecordsController controller = new AccessionRecordsController(mock.Object);
            AccessionRecord            arToAdd    = new AccessionRecord()
            {
                Item = new Item()
                {
                    Title = "Ignore this"
                }, AccessionRecordId = 1
            };

            mock.Setup(m => m.Add(It.IsAny <AccessionRecord>()));

            controller.Create(arToAdd);
            mock.Verify(m => m.Add(It.IsAny <AccessionRecord>()), Times.Once);
        }
예제 #8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AccessionRecord = await _context.AccessionRecord.FindAsync(id);

            if (AccessionRecord != null)
            {
                _context.AccessionRecord.Remove(AccessionRecord);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public void TestGetUnIssuedAccRecords()
        {
            // For this test, we set all issuedItems as "Returned"
            foreach (var i in issuedItems)
            {
                i.IsReturned = true;
            }

            // This adds an accession record for a copy that is issued
            AccessionRecord issuedRecord = new AccessionRecord()
            {
                Item = item, AccessionRecordId = 18
            };

            accessionRecords.Add(issuedRecord);

            // And add a new one, where "Returned" = false, i.e. it a member has borrowed it.
            // i.e, a member borrows the new copy, hence isReturned = false
            AccessionRecord neverIssued = new AccessionRecord()
            {
                Item = item, AccessionRecordId = 19
            };

            accessionRecords.Add(neverIssued);
            // Now we add an issuedItem which is borrowed. We're simulating a situation where all Items are returned,
            // and a member borrows one Item (whose Acc. Record is issuedRecord).
            issuedItems.Add(new IssuedItem()
            {
                AccessionRecord = issuedRecord, IsReturned = false
            });

            var service = new IssuedItemService(mockContext.Object);

            IEnumerable <int> recordIds = service.GetAllIssuableAccRecords().Select(r => r.AccessionRecordId);

            foreach (var rec in recordIds)
            {
                Debug.WriteLine(rec);
            }

            // Assert that the record that was never issued is also included
            Assert.IsTrue(recordIds.Contains(neverIssued.AccessionRecordId));
            // Assert that the returned Acession Record is NOT included
            Assert.IsFalse(recordIds.Contains(issuedRecord.AccessionRecordId));
        }
예제 #10
0
 public void OnGet()
 {
     Records         = _context.AccessionRecord.ToList();
     ReferenceStrain = Records.Single(x => x.Id == -1);
 }