public IdentityCompany GetById(int Id) { var sqlCmd = @"Company_GetById"; IdentityCompany info = null; var paramaters = new Dictionary <string, object> { { "Id", Id } }; try { using (var conn = new SqlConnection(_connectionString)) { using (var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, paramaters)) { if (reader.Read()) { info = ExtractCompanyData(reader); } } } } catch (Exception ex) { var strError = "Failed to execute Company_GetById. Error: " + ex.Message; throw new CustomSQLException(strError); } return(info); }
public bool Update(IdentityCompany identity) { var sqlCmd = @"Company_Update"; var paramaters = new Dictionary <string, object> { { "Id", identity.Id }, { "Code", identity.Code }, { "Name", identity.Name }, { "CountryId", identity.CountryId }, { "ProvinceId", identity.ProvinceId }, { "DistrictId", identity.DistrictId }, { "Address", identity.Address }, { "Email", identity.Email }, { "Phone", identity.PageIndex }, { "IsEPE", identity.IsEPE }, { "Status", identity.Status }, }; try { using (var conn = new SqlConnection(_connectionString)) { MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, paramaters); } } catch (Exception ex) { var strError = "Failed to execute Company_Update. Error: " + ex.Message; throw new CustomSQLException(strError); } return(true); }
public List <IdentityCompany> GetByPage(IdentityCompany filter, int currentPage, int pageSize) { var sqlCmd = @"Company_GetByPage"; List <IdentityCompany> listdata = null; int offset = (currentPage - 1) * pageSize; var parameters = new Dictionary <string, object> { { "@Keyword", filter.Keyword }, { "@Adress", filter.Address }, { "@Offset", offset }, { "@PageSize", pageSize }, }; try { using (var conn = new SqlConnection(_connectionString)) { using (var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters)) { listdata = ParsingListFromReader(reader); } } } catch (Exception ex) { var strError = "Failed to execute Company_GetByPage. Error: " + ex.Message; throw new CustomSQLException(strError); } return(listdata); }
//[AccessRoleChecker] public ActionResult Index(ManageCompanyModel 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 IdentityCompany { Keyword = !string.IsNullOrEmpty(model.Keyword) ? model.Keyword.Trim() : null, //Status = model.Status == null ? -1 : (int)model.Status, //ProductCategoryId = model.ProductCategoryId == null ? 0 : (int)model.ProductCategoryId, //ProviderId = model.ProviderId == null ? 0 : (int)model.ProviderId Address = !string.IsNullOrEmpty(model.Address) ? model.Address.Trim() : null, }; try { model.Countrys = CommonHelpers.GetListCountry(); model.Provinces = CommonHelpers.GetListProvince(); model.Districts = CommonHelpers.GetListDistrict(); //model.Provinces = CommonHelpers.GetProvinceByCountry(model.ProvinceId); //model.Districts = CommonHelpers.GetDistrictByProvince(model.DistrictId); 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)); }
// public IdentityCompany ExtractCreateFormData(CompanyCreateModel formData) { var myIdentity = new IdentityCompany(); myIdentity.Code = formData.Code; myIdentity.Name = formData.Name; myIdentity.CountryId = formData.CountryId; myIdentity.ProvinceId = formData.ProvinceId; myIdentity.DistrictId = formData.DistrictId; myIdentity.Address = formData.Address; myIdentity.Email = formData.Email; myIdentity.Phone = formData.Phone; myIdentity.IsEPE = formData.IsEPE; myIdentity.Status = formData.Status; return(myIdentity); }
public CompanyEditModel RenderEditModel(IdentityCompany identity) { var editModel = new CompanyEditModel(); editModel.Code = identity.Code; editModel.Name = identity.Name; editModel.CountryId = identity.CountryId; editModel.ProvinceId = identity.ProvinceId; editModel.DistrictId = identity.DistrictId; editModel.Countrys = CommonHelpers.GetListCountry(); editModel.Provinces = CommonHelpers.GetProvinceByCountry(identity.CountryId); editModel.Districts = CommonHelpers.GetDistrictByProvince(identity.ProvinceId); editModel.Address = identity.Address; editModel.Email = identity.Email; editModel.Phone = identity.Phone; editModel.IsEPE = identity.IsEPE; editModel.Status = identity.Status; return(editModel); }
public static IdentityCompany ExtractCompanyData(IDataReader reader) { var record = new IdentityCompany(); //Seperate properties; record.Id = Utils.ConvertToInt32(reader["Id"]); record.Code = reader["Code"].ToString(); record.Name = reader["Name"].ToString(); record.CountryId = Utils.ConvertToInt32(reader["CountryId"]); record.ProvinceId = Utils.ConvertToInt32(reader["ProvinceId"]); record.DistrictId = Utils.ConvertToInt32(reader["DistrictId"]); record.Address = reader["Address"].ToString(); record.Email = reader["Email"].ToString(); record.Phone = reader["Phone"].ToString(); //record.Lat = reader["Lat"].ToString(); //record.Long = reader["Long"].ToString(); record.IsEPE = Utils.ConvertToBoolean(reader["IsEPE"]); record.CreatedDate = reader["CreatedDate"] == DBNull.Value ? null : (DateTime?)reader["CreatedDate"]; record.Status = Utils.ConvertToInt32(reader["Status"]); return(record); }
public int Insert(IdentityCompany identity) { var sqlCmd = @"Company_Insert"; var newId = 0; var paramaters = new Dictionary <string, object> { { "Code", identity.Code }, { "Name", identity.Name }, { "CountryId", identity.CountryId }, { "ProvinceId", identity.ProvinceId }, { "DistrictId", identity.DistrictId }, { "Address", identity.Address }, { "Email", identity.Email }, { "Phone", identity.Phone }, { "IsEPE", identity.IsEPE }, { "Status", identity.Status }, }; try { using (var connn = new SqlConnection(_connectionString)) { var returnObj = MsSqlHelper.ExecuteScalar(connn, CommandType.StoredProcedure, sqlCmd, paramaters); newId = Convert.ToInt32(returnObj); } } catch (Exception ex) { var strError = "Failed to execute Company_Insert. Error: " + ex.Message; throw new CustomSQLException(strError); } return(newId); }
public bool Update(IdentityCompany identity) { return(myRepository.Update(identity)); }
public int Insert(IdentityCompany identity) { return(myRepository.Insert(identity)); }
public List <IdentityCompany> GetByPage(IdentityCompany filter, int currentPage, int pageSize) { return(myRepository.GetByPage(filter, currentPage, pageSize)); }