コード例 #1
0
        public void Update(InmateUnit inmateUnit)
        {
            inmateUnit = Validate(inmateUnit);

            _inmateUnits.Attach(inmateUnit);
            _repository.Entry(inmateUnit).State = EntityState.Modified;
            _repository.SaveChanges();
        }
コード例 #2
0
        public InmateUnit Insert(InmateUnit inmateUnit)
        {
            inmateUnit = Validate(inmateUnit);

            _inmateUnits.Add(inmateUnit);
            _repository.SaveChanges();
            _repository.Entry(inmateUnit).GetDatabaseValues();
            return inmateUnit;
        }
コード例 #3
0
        public void Delete(InmateUnit inmateUnit)
        {
            if (inmateUnit.Patrons.Any())
                throw new BusinessLogicException(string.Format("This inmate unit cannot be deleted because there are {0} patron(s) associated with it.", inmateUnit.Patrons.Count));

            _inmateUnits.Attach(inmateUnit);
            _repository.Entry(inmateUnit).State = EntityState.Deleted;
            _repository.SaveChanges();
        }
コード例 #4
0
        private InmateUnit Validate(InmateUnit inmateUnit)
        {
            // Set optional fields to null so that we don't save empty strings in the db.

            if (!string.IsNullOrWhiteSpace(inmateUnit.Address1))
                inmateUnit.Address1 = inmateUnit.Address1.Trim();
            else
                throw new BusinessLogicException("An address is required for all inmate units.");

            if (!string.IsNullOrWhiteSpace(inmateUnit.Address2))
                inmateUnit.Address2 = inmateUnit.Address2.Trim();
            else
                inmateUnit.Address2 = null;

            if (!string.IsNullOrWhiteSpace(inmateUnit.City))
                inmateUnit.City = inmateUnit.City.Trim();
            else
                throw new BusinessLogicException("A city is required for all inmate units.");

            if (!string.IsNullOrWhiteSpace(inmateUnit.State))
                inmateUnit.State = inmateUnit.State.Trim();
            else
                throw new BusinessLogicException("A state is required for all inmate units.");

            if (!string.IsNullOrWhiteSpace(inmateUnit.TDCJUnitNumber))
                inmateUnit.TDCJUnitNumber = inmateUnit.TDCJUnitNumber.Trim();
            else
                inmateUnit.TDCJUnitNumber = null;

            if (!string.IsNullOrWhiteSpace(inmateUnit.UnitName))
                inmateUnit.UnitName = inmateUnit.UnitName.Trim();
            else
                throw new BusinessLogicException("A unit name is required for all inmate units.");

            if (!string.IsNullOrWhiteSpace(inmateUnit.Zip))
                inmateUnit.Zip = inmateUnit.Zip.Trim();
            else
                throw new BusinessLogicException("A zip code is required for all inmate units.");

            return inmateUnit;
        }