Example #1
0
        public void AccessAttemptionNavigationPropertiesWork()
        {
            AccessAttemption accessAttemption = new AccessAttemption
            {
                Card = new Card
                {
                    Employee = new Employee
                    {
                        FirstName    = "FirstName",
                        SecondName   = "SecondName",
                        JobTitle     = "Job",
                        VisitingRule = new VisitingRule()
                        {
                            Description = "Description"
                        }
                    },
                },
                PassagePoint = new PassagePoint
                {
                    Address = "Address"
                },
                SuccessStatus  = true,
                IsEnter        = true,
                AttemptionTime = DateTime.Now
            };

            employeeTimeControlDataContext.AccessAttemptionSet.Add(accessAttemption);
            Assert.NotEqual(0, employeeTimeControlDataContext.SaveChanges());

            accessAttemption = employeeTimeControlDataContext.AccessAttemptionSet.Find(accessAttemption.AccessAttemptionId);

            Assert.NotNull(accessAttemption);
            Assert.NotNull(accessAttemption.PassagePoint);
            Assert.NotNull(accessAttemption.Card);
        }
        public IHttpActionResult PutAccessAttemption(int id, AccessAttemption accessAttemption)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != accessAttemption.AccessAttemptionId)
            {
                return(BadRequest());
            }

            db.Entry(accessAttemption).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccessAttemptionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetAccessAttemption(int id)
        {
            AccessAttemption accessAttemption = db.AccessAttemptionSet.Find(id);

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

            return(Ok(accessAttemption));
        }
        public IHttpActionResult PostAccessAttemption(AccessAttemption accessAttemption)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AccessAttemptionSet.Add(accessAttemption);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = accessAttemption.AccessAttemptionId }, accessAttemption));
        }
        public IHttpActionResult DeleteAccessAttemption(int id)
        {
            AccessAttemption accessAttemption = db.AccessAttemptionSet.Find(id);

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

            db.AccessAttemptionSet.Remove(accessAttemption);
            db.SaveChanges();

            return(Ok(accessAttemption));
        }