public UnitOfMeasure AddUnitOfMeasure(UnitOfMeasure oUnitOfMeasure)
        {
            try
            {
                int operationType = Convert.ToInt32(oUnitOfMeasure.UnitID == 0 ? OperationType.Insert : OperationType.Update);

                using (IDbConnection con = new SqlConnection(AppSettings.ConnectionStrings))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    var oUnitOfMeasureList = con.Query <UnitOfMeasure>("sp_UnitOfMeasure",
                                                                       _unitOfMeasure.SetParameters(oUnitOfMeasure, operationType),
                                                                       commandType: CommandType.StoredProcedure);

                    if (oUnitOfMeasureList != null && oUnitOfMeasureList.Count() > 0)
                    {
                        _unitOfMeasure = oUnitOfMeasureList.FirstOrDefault();
                    }
                }
            }
            catch (Exception ex)
            {
                _psgc.Message = ex.Message;
            }

            return(_unitOfMeasure);
        }
        public UnitOfMeasure GetUnitOfMeasure(int unitId)
        {
            _unitOfMeasure = new UnitOfMeasure()
            {
                UnitID = unitId
            };

            try
            {
                int operationType = Convert.ToInt32(OperationType.SelectSpecific);

                using (IDbConnection con = new SqlConnection(AppSettings.ConnectionStrings))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    var oUnitOfMeasure = con.Query <UnitOfMeasure>("sp_UnitOfMeasure",
                                                                   _unitOfMeasure.SetParameters(_unitOfMeasure, operationType),
                                                                   commandType: CommandType.StoredProcedure).ToList();

                    if (oUnitOfMeasure != null && oUnitOfMeasure.Count() > 0)
                    {
                        _unitOfMeasure = oUnitOfMeasure.SingleOrDefault();
                    }
                }
            }
            catch (Exception ex)
            {
                _psgc.Message = ex.Message;
            }

            return(_unitOfMeasure);
        }
        public string Delete(int unitId)
        {
            string message = "";

            try
            {
                _unitOfMeasure = new UnitOfMeasure()
                {
                    UnitID = unitId
                };

                using (IDbConnection con = new SqlConnection(AppSettings.ConnectionStrings))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    var oUnitOfMeasure = con.Query <UnitOfMeasure>("sp_UnitOfMeasure",
                                                                   _unitOfMeasure.SetParameters(_unitOfMeasure, (int)OperationType.Delete),
                                                                   commandType: CommandType.StoredProcedure);

                    if (oUnitOfMeasure != null && oUnitOfMeasure.Count() > 0)
                    {
                        _unitOfMeasure = oUnitOfMeasure.FirstOrDefault();

                        message = "Data Deleted!";
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            return(message);
        }