public IdentityUnit GetById(int Id) { var info = new IdentityUnit(); var sqlCmd = @"Unit_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 = ExtractUnitData(reader); } } } } catch (Exception ex) { var strError = "Failed to execute Unit_GetById. Error: " + ex.Message; throw new CustomSQLException(strError); } return(info); }
public bool Update(IdentityUnit identity) { //Common syntax var sqlCmd = @"Unit_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 Unit_Update. Error: " + ex.Message; throw new CustomSQLException(strError); } return(true); }
public int Insert(IdentityUnit identity) { //Common syntax var sqlCmd = @"Unit_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 Unit_Insert. Error: " + ex.Message; throw new CustomSQLException(strError); } return(newId); }
private IdentityUnit ExtractCreateFormData(UnitCreateModel formData) { var myIdetity = new IdentityUnit(); myIdetity.Name = formData.Name; myIdetity.Code = formData.Code; myIdetity.Status = formData.Status; return(myIdetity); }
private UnitEditModel RenderEditModel(IdentityUnit identity) { var editModel = new UnitEditModel(); editModel.Id = identity.Id; editModel.Name = identity.Name; editModel.Code = identity.Code; editModel.Status = identity.Status; return(editModel); }
public ActionResult Index(ManageUnitModel 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 IdentityUnit { 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)); }
private IdentityUnit ExtractUnitData(IDataReader reader) { var record = new IdentityUnit(); //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); }
public List <IdentityUnit> GetByPage(IdentityUnit filter, int currentPage, int pageSize) { //Common syntax var sqlCmd = @"Unit_GetByPage"; List <IdentityUnit> 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 = ParsingListUnitFromReader(reader); } } } catch (Exception ex) { var strError = "Failed to execute Unit_GetByPage. Error: " + ex.Message; throw new CustomSQLException(strError); } return(listData); }
public bool Update(IdentityUnit identity) { return(myRepository.Update(identity)); }
public int Insert(IdentityUnit identity) { return(myRepository.Insert(identity)); }
public List <IdentityUnit> GetByPage(IdentityUnit filter, int currentPage, int pageSize) { return(myRepository.GetByPage(filter, currentPage, pageSize)); }