Esempio n. 1
0
        public IHttpActionResult Putstaff(int id, staff staff)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != staff.ID)
            {
                return BadRequest();
            }


            try
            {
                _staffBL.Put(staff);
            }
            catch
            {
                if (!staffExists(id))
                {
                    return NotFound();
                }
                throw;
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Esempio n. 2
0
        public void Put(staff staff)
        {
            var staffMember = _context.staffs.Single(s => s.ID == staff.ID);
            staffMember.FirstName = staff.FirstName;
            staffMember.LastName = staff.LastName;
            staffMember.Email = staff.Email;
            staffMember.PhoneNumber = staff.PhoneNumber;

            _context.SaveChanges();
        }
Esempio n. 3
0
        public async Task<IHttpActionResult> Poststaff(staff staff)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _staffBL.Post(staff);

            return CreatedAtRoute("DefaultApi", new {id = staff.ID}, staff);
        }
Esempio n. 4
0
 public void Post_Staff_Object_To_DB()
 {
     var mockSet = new Mock<DbSet<staff>>();
     var mockContext = new Mock<StaffAppContext>();
     mockContext.Setup(m => m.staffs).Returns(mockSet.Object);
     var member = new staff
                 {
                     Email = "*****@*****.**",
                     FirstName = "Andy",
                     ID = 4,
                     LastName = "Nicoll"
                 };
     var staffRepo = new staffDAO(mockContext.Object);
     staffRepo.Post(member);
     mockSet.Verify(m => m.Add(It.IsAny<staff>()), Times.Once());
     mockContext.Verify(m => m.SaveChanges(), Times.Once());
 }
Esempio n. 5
0
        public void Put_Staff_Object_To_DB()
        {
            var data = new List<staff>{
            new staff
            {
                Email = "*****@*****.**",
                FirstName = "Andy",
                ID = 4,
                LastName = "Nicoll"
            },
            new staff{
                Email = "*****@*****.**",
                FirstName = "Asdndy",
                ID = 44,
                LastName = "Nidcoll"
            }
            }.AsQueryable();

            var mockSet = new Mock<DbSet<staff>>();
            mockSet.As<IQueryable<staff>>().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As<IQueryable<staff>>().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As<IQueryable<staff>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As<IQueryable<staff>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock<StaffAppContext>();
            mockContext.Setup(m => m.staffs).Returns(mockSet.Object);

            var singleStaff = new staff
            {
                Email = "*****@*****.**",
                FirstName = "Andy",
                ID = 4,
                LastName = "Nicoll"
            };

            var service = new staffDAO(mockContext.Object);
            service.Put(singleStaff);

            Assert.AreEqual("Nicoll", singleStaff.LastName);
            Assert.AreEqual("*****@*****.**", singleStaff.Email);
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Esempio n. 6
0
        public void Post(staff staff)
        {
            _context.staffs.Add(staff);

            _context.SaveChanges();
        }
Esempio n. 7
0
 public void Put(staff staff)
 {
     _staffDAO.Put(staff);
 }
Esempio n. 8
0
 public void Post(staff staff)
 {
     _staffDAO.Post(staff);
 }
Esempio n. 9
0
 public void Post_Staff_Object_To_DB()
 {
     Mock<IStaffDAO> mockStaffDAO = new Mock<IStaffDAO>();
     mockStaffDAO.Setup(m => m.Post(It.IsAny<staff>()));
     StaffBL staff = new StaffBL(mockStaffDAO.Object);
     var member = new staff
     {
         Email = "*****@*****.**",
         FirstName = "andrew",
         LastName = "nick"
     };
     staff.Post(member);
 }