コード例 #1
0
        public void InvalidPut()
        {
            // Arrange
            bool res              = false;
            SQLiteServiceBase db  = new SQLiteServiceBase();
            RestrictedInfo    obj = GetInvalidObject();

            // Act
            try
            {
                int len = 0;
                if (db.GetRestrictedInfo() != null)
                {
                    foreach (var c in db.GetRestrictedInfo())
                    {
                        len++;
                    }
                }
                if (len != 0)
                {
                    db.Edit(len - 1, obj);
                }
            }
            catch (Exception)
            {
                res = true;
            }

            // Assert
            Assert.IsFalse(res);
        }
コード例 #2
0
        RestrictedInfo GetInvalidObject()
        {
            RestrictedInfo obj = new RestrictedInfo();

            obj.DateOfBirth = "13.12.2001";
            obj.DateOfDeath = "unknown";

            return(obj);
        }
コード例 #3
0
        public void DeleteRestrictedInfo(int id)
        {
            RestrictedInfo obj = dataBase.RestrictedInfo.Find(id);

            if (obj != null)
            {
                dataBase.RestrictedInfo.Remove(obj);
                Update();
            }
        }
コード例 #4
0
        RestrictedInfo GetValidObject()
        {
            RestrictedInfo obj = new RestrictedInfo();

            obj.DateOfBirth   = "13.12.2001";
            obj.DateOfDeath   = "unknown";
            obj.GovernmentId  = "why Id is string?";
            obj.PassportId    = "MP12333";
            obj.HireDire      = "what is it";
            obj.SeniorityCode = 112233;

            return(obj);
        }
コード例 #5
0
        public RestrictedInfo GetRestrictedInfoId(int id)
        {
            RestrictedInfo obj = null;

            foreach (RestrictedInfo o in dataBase.RestrictedInfo)
            {
                if (o.== id)
                {
                    obj = o; break;
                }
            }
            return(obj);
        }
コード例 #6
0
        // PUT api/RestrictedInfo/{id}
        public IHttpActionResult Put(int id, [FromBody] RestrictedInfo value)
        {
            try
            {
                _db.Edit(id, value);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(nameof(RestrictedInfo), ex.Message);

                return(BadRequest(ModelState));
            }

            return(Ok());
        }
コード例 #7
0
        // POST api/RestrictedInfo
        public IHttpActionResult Post([FromBody] RestrictedInfo value)
        {
            try
            {
                db.Add(value);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(nameof(Country), ex.Message);

                return(BadRequest(ModelState));
            }

            return(Ok());
        }
コード例 #8
0
        public void Edit(int id, RestrictedInfo obj)
        {
            using (var context = new ApplicationContext())
            {
                var temp = context.RestrictedInfo.FirstOrDefault(_ => _.== id);
                try
                {
                    if (temp != null)
                    {
                        //
                        //  change properties
                        //

                        context.SaveChanges();
                    }
                }
                catch (Exception) { /*TO DO*/ }
            }
        }
コード例 #9
0
        public void InvalidPost()
        {
            // Arrange
            bool res              = false;
            SQLiteServiceBase db  = new SQLiteServiceBase();
            RestrictedInfo    obj = GetInvalidObject();

            // Act
            try
            {
                db.Add(obj);
            }
            catch (Exception)
            {
                res = true;
            }

            // Assert
            Assert.IsTrue(res);
        }
コード例 #10
0
        public void Edit(int id, RestrictedInfo obj)
        {
            using (var context = new ApplicationContext())
            {
                var temp = context.RestrictedInfo.FirstOrDefault(_ => _.PersonId == id);
                try
                {
                    if (temp != null)
                    {
                        temp.DateOfBirth   = obj.DateOfBirth;
                        temp.DateOfDeath   = obj.DateOfDeath;
                        temp.GovernmentId  = obj.GovernmentId;
                        temp.PassportId    = obj.PassportId;
                        temp.HireDire      = obj.HireDire;
                        temp.SeniorityCode = obj.SeniorityCode;

                        context.SaveChanges();
                    }
                }
                catch (Exception) { /*TO DO*/ }
            }
        }
コード例 #11
0
 public void Add(RestrictedInfo obj)
 {
     dataBase.RestrictedInfo.Add(obj);
     Update();
 }