public static PhoneCall MapDalInterfacePhoneCallToDataAccessPhoneCall(DalInterface.Models.PhoneCall iPhoneCall)
        {
            PhoneCall daPhoneCall = new PhoneCall();

            daPhoneCall.Id = iPhoneCall.Id;
            daPhoneCall.SSN = iPhoneCall.SSN;
            daPhoneCall.MarkedToDelete = bool.Parse(iPhoneCall.MarkedToDelete);

            return daPhoneCall;
        }
Ejemplo n.º 2
0
        public static Entity MapDalInterfaceEntityToDataAccessEntity(DalInterface.Models.Entity iEntity)
        {
            Entity daEntity = new Entity();

            daEntity.Id = iEntity.Id;
            daEntity.FirstName = iEntity.FirstName;
            daEntity.LastName = iEntity.LastName;
            daEntity.MarkedToDelete = bool.Parse(iEntity.MarkedToDelete);

            return daEntity;
        }
Ejemplo n.º 3
0
        public static DalInterface GetDalInterface()
        {
            DalInterface result = null;

            switch (Config.Instance.DBType)
            {
            case Config.DB_TYPE_MYSQL:
                result = mysqlInterface;
                break;

            case Config.DB_TYPE_SQLITE:
                result = sqliteInterface;
                break;

            case Config.DB_TYPE_SQLSERVER:
                result = sqlserverInterface;
                break;
            }
            return(result);
        }
        // Create a new Entity
        public DalInterface.Models.Entity Create(DalInterface.Models.Entity iEntity)
        {
            var result = 0;

            Entity daEntity = EntityMapper.MapDalInterfaceEntityToDataAccessEntity(iEntity);

            try {
                this._dbContext.Entities.Add(daEntity);
                result = this._dbContext.SaveChanges();

                // DbContext sets Id to the new Identity value.
                iEntity.Id = daEntity.Id;
            }
            catch (System.Data.UpdateException ex) {
                if (ex.InnerException != null && ex.InnerException is System.Data.SqlClient.SqlException
                   && ((System.Data.SqlClient.SqlException)ex.InnerException).ErrorCode == 8152)
                    throw ex.InnerException;
                else
                    throw ex;
            }

            return iEntity;
        }
        // Create a new PhoneCall
        public DalInterface.Models.PhoneCall Create(DalInterface.Models.PhoneCall iPhoneCall)
        {
            var result = 0;

            PhoneCall daPhoneCall = PhoneCallMapper.MapDalInterfacePhoneCallToDataAccessPhoneCall(iPhoneCall);

            try {
                this._dbContext.PhoneCalls.Add(daPhoneCall);
                result = this._dbContext.SaveChanges();

                // DbContext sets Id to the new Identity value.
                iPhoneCall.Id = daPhoneCall.Id;
            }
            catch (System.Data.UpdateException ex) {
                if (ex.InnerException != null && ex.InnerException is System.Data.SqlClient.SqlException
                   && ((System.Data.SqlClient.SqlException)ex.InnerException).ErrorCode == 8152)
                    throw ex.InnerException;
                else
                    throw ex;
            }

            return iPhoneCall;
        }
        // Update an existing Entity
        public int Update(DalInterface.Models.Entity iEntity)
        {
            var result = 0;
            Entity daLoadedEntity = null;
            Entity daEntity = EntityMapper.MapDalInterfaceEntityToDataAccessEntity(iEntity);

            try {
                // Load object into context (entity framework)
                daLoadedEntity = _dbContext.Entities.Where(pc => pc.Id == iEntity.Id).FirstOrDefault();

                if (daLoadedEntity == null) { //not found?
                    throw new Exception("Entity not found to update");
                }
                else {
                    // Update
                    _dbContext.Entry(daLoadedEntity).CurrentValues.SetValues(daEntity);
                }

                // Save in data access (entity framework)
                result = this._dbContext.SaveChanges();
            }
            catch (System.Data.UpdateException ex) {
                if (ex.InnerException != null && ex.InnerException is System.Data.SqlClient.SqlException
                   && ((System.Data.SqlClient.SqlException)ex.InnerException).ErrorCode == 8152)
                    throw ex.InnerException;
                else
                    throw ex;
            }

            return result;
        }
Ejemplo n.º 7
0
 public DeviceDAL()
 {
     dh = new DALHelper();
     di = DALFactory.GetDalInterface();
 }
Ejemplo n.º 8
0
 public DeviceSwitchDAL()
 {
     di = DALFactory.GetDalInterface();
 }