Exemplo n.º 1
0
        public IdentityDevice GetById(int Id)
        {
            var info   = new IdentityDevice();
            var sqlCmd = @"Device_GetById";

            var parameters = new Dictionary <string, object>
            {
                { "@Id", Id }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    using (var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters))
                    {
                        while (reader.Read())
                        {
                            info = ExtractDeviceData(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Device_GetById. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }
            return(info);
        }
Exemplo n.º 2
0
        public static int RegisterNewDevice(IdentityDevice deviceInfo, out bool isNew)
        {
            var newId = 0;

            isNew = false;
            try
            {
                var myStore = GlobalContainer.IocContainer.Resolve <IStoreDevice>();

                if (deviceInfo != null)
                {
                    newId = myStore.RegisterNewDevice(deviceInfo, out isNew);
                    if (isNew)
                    {
                        //Clear cache
                        CachingHelpers.ClearDeviceCache();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Could not RegisterNewDevice: " + ex.ToString());
            }

            return(newId);
        }
Exemplo n.º 3
0
        public bool Update(IdentityDevice identity)
        {
            //Common syntax
            var sqlCmd = @"Device_Update";

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@Id", identity.Id },
                { "@Name", identity.Name },
                { "@Code", identity.Code },
                //{"@LastUpdatedBy", identity.LastUpdatedBy},
                { "@Status", identity.Status }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, parameters);
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Device_Update. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(true);
        }
Exemplo n.º 4
0
        public int Insert(IdentityDevice identity)
        {
            //Common syntax
            var sqlCmd = @"Device_Insert";
            var newId  = 0;

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@Name", identity.Name },
                { "@Code", identity.Code }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    var returnObj = MsSqlHelper.ExecuteScalar(conn, CommandType.StoredProcedure, sqlCmd, parameters);

                    newId = Convert.ToInt32(returnObj);
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Device_Insert. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(newId);
        }
Exemplo n.º 5
0
        public int RegisterNewDevice(IdentityDevice identity, out bool isNew)
        {
            //Common syntax
            var sqlCmd      = @"Device_RegisterNewDevice";
            var newId       = 0;
            var hasInserted = 0;

            isNew = false;

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@Name", identity.Name },
                { "@Code", identity.Code }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters);
                    if (reader.Read())
                    {
                        newId = Convert.ToInt32(reader[0]);
                    }

                    if (reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            hasInserted = Utils.ConvertToInt32(reader[0]);
                            if (hasInserted == 1)
                            {
                                isNew = true;
                            }
                            else
                            {
                                isNew = false;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute RegisterNewDevice. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(newId);
        }
Exemplo n.º 6
0
        private IdentityDevice ExtractDeviceData(IDataReader reader)
        {
            var record = new IdentityDevice();

            //Seperate properties
            record.Id   = Utils.ConvertToInt32(reader["Id"]);
            record.Name = reader["Name"].ToString();
            record.Code = reader["Code"].ToString();

            //record.CreatedBy = reader["CreatedBy"].ToString();
            record.CreatedDate = reader["CreatedDate"] == DBNull.Value ? null : (DateTime?)reader["CreatedDate"];
            //record.LastUpdated = reader["LastUpdated"] == DBNull.Value ? null : (DateTime?)reader["LastUpdated"];
            //record.LastUpdatedBy = reader["LastUpdatedBy"].ToString();
            record.Status = Utils.ConvertToInt32(reader["Status"]);

            return(record);
        }
Exemplo n.º 7
0
        private int RegisterNewDevice()
        {
            var deviceId = 0;
            var isNew    = false;

            try
            {
                var deviceInfo = new IdentityDevice();
                deviceInfo.Name = System.Environment.MachineName;
                deviceId        = CommonHelpers.RegisterNewDevice(deviceInfo, out isNew);
            }
            catch (Exception ex)
            {
                logger.Error("Failed to RegisterNewDevice because: " + ex.ToString());
            }

            return(deviceId);
        }
Exemplo n.º 8
0
        public List <IdentityDevice> GetByPage(IdentityDevice filter, int currentPage, int pageSize)
        {
            //Common syntax
            var sqlCmd = @"Device_GetByPage";
            List <IdentityDevice> listData = null;

            //For paging
            int offset = (currentPage - 1) * pageSize;

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@Keyword", filter.Keyword },
                { "@Status", filter.Status },
                { "@Offset", offset },
                { "@PageSize", pageSize },
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    using (var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters))
                    {
                        listData = ParsingListDeviceFromReader(reader);
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Device_GetByPage. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(listData);
        }
Exemplo n.º 9
0
 public bool Update(IdentityDevice identity)
 {
     return(myRepository.Update(identity));
 }
Exemplo n.º 10
0
 public int RegisterNewDevice(IdentityDevice identity, out bool isNew)
 {
     return(myRepository.RegisterNewDevice(identity, out isNew));
 }
Exemplo n.º 11
0
 public int Insert(IdentityDevice identity)
 {
     return(myRepository.Insert(identity));
 }
Exemplo n.º 12
0
 public List <IdentityDevice> GetByPage(IdentityDevice filter, int currentPage, int pageSize)
 {
     return(myRepository.GetByPage(filter, currentPage, pageSize));
 }