Example #1
0
        public IdentityProductCategory GetById(int Id)
        {
            var info   = new IdentityProductCategory();
            var sqlCmd = @"ProductCategory_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 = ExtractProductCategoryData(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute ProductCategory_GetById. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }
            return(info);
        }
Example #2
0
        public bool Update(IdentityProductCategory identity)
        {
            //Common syntax
            var sqlCmd = @"ProductCategory_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 ProductCategory_Update. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(true);
        }
Example #3
0
        public int Insert(IdentityProductCategory identity)
        {
            //Common syntax
            var sqlCmd = @"ProductCategory_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 ProductCategory_Insert. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(newId);
        }
Example #4
0
        private IdentityProductCategory ExtractCreateFormData(ProductCategoryCreateModel formData)
        {
            var myIdetity = new IdentityProductCategory();

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

            return(myIdetity);
        }
Example #5
0
        private ProductCategoryEditModel RenderEditModel(IdentityProductCategory identity)
        {
            var editModel = new ProductCategoryEditModel();

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

            return(editModel);
        }
Example #6
0
        public ActionResult Index(ManageProductCategoryModel 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 IdentityProductCategory
            {
                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));
        }
Example #7
0
        private IdentityProductCategory ExtractProductCategoryData(IDataReader reader)
        {
            var record = new IdentityProductCategory();

            //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);
        }
Example #8
0
        public List <IdentityProductCategory> GetByPage(IdentityProductCategory filter, int currentPage, int pageSize)
        {
            //Common syntax
            var sqlCmd = @"ProductCategory_GetByPage";
            List <IdentityProductCategory> 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 = ParsingListProductCategoryFromReader(reader);
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute ProductCategory_GetByPage. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(listData);
        }
Example #9
0
 public bool Update(IdentityProductCategory identity)
 {
     return(myRepository.Update(identity));
 }
Example #10
0
 public int Insert(IdentityProductCategory identity)
 {
     return(myRepository.Insert(identity));
 }
Example #11
0
 public List <IdentityProductCategory> GetByPage(IdentityProductCategory filter, int currentPage, int pageSize)
 {
     return(myRepository.GetByPage(filter, currentPage, pageSize));
 }