Esempio n. 1
0
        public IdentityCurrency GetById(int Id)
        {
            var info   = new IdentityCurrency();
            var sqlCmd = @"Currency_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 = ExtractCurrencyData(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Currency_GetById. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }
            return(info);
        }
Esempio n. 2
0
        public int Insert(IdentityCurrency identity)
        {
            //Common syntax
            var sqlCmd = @"Currency_Insert";
            var newId  = 0;

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

            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 Currency_Insert. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(newId);
        }
Esempio n. 3
0
        public bool Update(IdentityCurrency identity)
        {
            //Common syntax
            var sqlCmd = @"Currency_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 Currency_Update. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(true);
        }
Esempio n. 4
0
        private IdentityCurrency ExtractCreateFormData(CurrencyCreateModel formData)
        {
            var myIdetity = new IdentityCurrency();

            myIdetity.Name   = formData.Name;
            myIdetity.Code   = formData.Code;
            myIdetity.Status = formData.Status;

            return(myIdetity);
        }
Esempio n. 5
0
        private CurrencyEditModel RenderEditModel(IdentityCurrency identity)
        {
            var editModel = new CurrencyEditModel();

            editModel.Id     = identity.Id;
            editModel.Name   = identity.Name;
            editModel.Code   = identity.Code;
            editModel.Status = identity.Status;

            return(editModel);
        }
Esempio n. 6
0
        private IdentityCurrency ExtractEditFormData(CurrencyEditModel formData)
        {
            var myIdetity = new IdentityCurrency();

            myIdetity.Id = formData.Id;

            myIdetity.Name   = formData.Name;
            myIdetity.Code   = formData.Code;
            myIdetity.Status = formData.Status;

            return(myIdetity);
        }
Esempio n. 7
0
        private IdentityCurrency ExtractCurrencyData(IDataReader reader)
        {
            var record = new IdentityCurrency();

            //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);
        }
Esempio n. 8
0
        public ActionResult Index(ManageCurrencyModel model)
        {
            int currentPage = 1;
            int pageSize    = SystemSettings.DefaultPageSize;

            if (string.IsNullOrEmpty(model.SearchExec))
            {
                model.SearchExec = "Y";
                if (!ModelState.IsValid)
                {
                    ModelState.Clear();
                }
            }

            if (Request["Page"] != null)
            {
                currentPage = Utils.ConvertToInt32(Request["Page"], 1);
            }

            var filter = new IdentityCurrency
            {
                Keyword = !string.IsNullOrEmpty(model.Keyword) ? model.Keyword.Trim() : null,
                Status  = model.Status == null ? -1 : (int)model.Status
            };

            try
            {
                model.SearchResults = _mainStore.GetByPage(filter, currentPage, SystemSettings.DefaultPageSize);
                if (model.SearchResults != null && model.SearchResults.Count > 0)
                {
                    model.TotalCount  = model.SearchResults[0].TotalCount;
                    model.CurrentPage = currentPage;
                    model.PageSize    = pageSize;
                }
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed to get data because: " + ex.ToString());

                return(View(model));
            }

            return(View(model));
        }
Esempio n. 9
0
        public List <IdentityCurrency> GetByPage(IdentityCurrency filter, int currentPage, int pageSize)
        {
            //Common syntax
            var sqlCmd = @"Currency_GetByPage";
            List <IdentityCurrency> 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 = ParsingListCurrencyFromReader(reader);
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Currency_GetByPage. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(listData);
        }
Esempio n. 10
0
 public bool Update(IdentityCurrency identity)
 {
     return(myRepository.Update(identity));
 }
Esempio n. 11
0
 public int Insert(IdentityCurrency identity)
 {
     return(myRepository.Insert(identity));
 }
Esempio n. 12
0
 public List <IdentityCurrency> GetByPage(IdentityCurrency filter, int currentPage, int pageSize)
 {
     return(myRepository.GetByPage(filter, currentPage, pageSize));
 }