public class NGODB
{
public static NGODetailsEntity GetNGODetailsById(string Id)
{
NGODetailsEntity objNGO = null;
try
{
string strQuery = @"<Where>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.SAPId + "'/><Value Type='Text'>" + Id + @"</Value></Eq>
</Where>";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
QueryBuilder queryBuilder = new QueryBuilder();
queryBuilder.QueryString = strQuery;
queryBuilder.ViewFields = "<FieldRef Name='" + NGODetailsEntity.FieldsName.Title + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyName + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.Country + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.Incentives + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.NGOUser + @"'/>";
SPQuery oQuery = Queries.GetSPQuery(queryBuilder);
SPList oList = web.Lists[NGODetailsEntity.ListName];
if (oList != null && oList.ItemCount > 0)
{
SPListItemCollection itemCollection = oList.GetItems(oQuery);
//Get collection data and add it with entity classes
if (itemCollection != null && itemCollection.Count > 0)
{
SPListItem item = itemCollection[0];
objNGO = new NGODetailsEntity();
objNGO.Title = item[NGODetailsEntity.FieldsName.Title].GetString();
objNGO.CompanyName = item[NGODetailsEntity.FieldsName.CompanyName].GetString();
objNGO.Incentives = item[NGODetailsEntity.FieldsName.Incentives].GetBoolean();
objNGO.NGOUser = item[NGODetailsEntity.FieldsName.NGOUser].GetBoolean();
}
}
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return objNGO;
}
public static List<NGODetailsEntity> GetActiveNGODetail()
{
List<NGODetailsEntity> objNGO = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
SPList oList = web.Lists[NGODetailsEntity.ListName];
if (oList != null && oList.ItemCount > 0)
{
SPQuery query = new SPQuery();
query.ViewFields = "<FieldRef Name='" + NGODetailsEntity.FieldsName.Title + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyName + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyType + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.NGOUser + @"'/>";
SPListItemCollection itemCollection = oList.GetItems(query);
//Get collection data and add it with entity classes
if (itemCollection != null && itemCollection.Count > 0)
{
objNGO = new List<NGODetailsEntity>();
NGODetailsEntity objNGONew = null;
for (int i = 0; i < itemCollection.Count; i++)
{
objNGONew = new NGODetailsEntity();
objNGONew.Title = itemCollection[i][NGODetailsEntity.FieldsName.Title].GetString();
objNGONew.Country = itemCollection[i][NGODetailsEntity.FieldsName.Country].GetString();
objNGONew.Incentives = itemCollection[i][NGODetailsEntity.FieldsName.Incentives].GetBoolean();
objNGONew.NGOUser = itemCollection[i][NGODetailsEntity.FieldsName.NGOUser].GetBoolean();
objNGO.Add(objNGONew);
}
}
}
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return objNGO;
}
public static List<UnverifiedNGOEntity> GetInActiveNGODetail()
{
List<UnverifiedNGOEntity> objUnverifiedNGO = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
SPList oList = web.Lists[UnverifiedNGOEntity.ListName];
if (oList != null && oList.ItemCount > 0)
{
SPQuery query = new SPQuery();
string strQuery = @"<OrderBy><FieldRef Name='" + UnverifiedNGOEntity.FieldsName.Title + @"' Ascending='False' /></OrderBy>";
query.ViewFields = "<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.Title + @"'/>
<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.CompanyType + @"'/>
<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.Country + @"'/>
<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.UserName + @"'/>
<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.UserDisplayName + @"'/> ";
SPListItemCollection itemCollection = oList.GetItems(query);
//Get collection data and add it with entity classes
if (itemCollection != null && itemCollection.Count > 0)
{
objUnverifiedNGO = new List<UnverifiedNGOEntity>();
UnverifiedNGOEntity objUnverifiedNGONew = null;
for (int i = 0; i < itemCollection.Count; i++)
{
objUnverifiedNGONew = new UnverifiedNGOEntity();
objUnverifiedNGONew.Title = itemCollection[i][UnverifiedNGOEntity.FieldsName.Title].GetString();
objUnverifiedNGONew.Title = itemCollection[i][UnverifiedNGOEntity.FieldsName.Title].GetString();
objUnverifiedNGONew.UserDisplayName = itemCollection[i][UnverifiedNGOEntity.FieldsName.UserDisplayName].GetString();
objUnverifiedNGO.Add(objUnverifiedNGONew);
}
}
}
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return objUnverifiedNGO;
}
public static List<NGODetailsEntity> GetFilterNGODetail(NGODetailsEntity objNGODetailsEntity)
{
List<NGODetailsEntity> objNGO = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
SPList oList = web.Lists[NGODetailsEntity.ListName];
if (oList != null && oList.ItemCount > 0)
{
SPQuery query = new SPQuery();
///caml query
///
string strQuery = @"<Where>
<And>
<And>
<And>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyName + "'/><Value Type='Text'>" + objNGODetailsEntity.CompanyName + @"</Value></Eq>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.State + "'/><Value Type='Text'>" + objNGODetailsEntity.State + @"</Value></Eq>
</And>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.Country + "'/><Value Type='Text'>" + objNGODetailsEntity.Country + @"</Value></Eq>
</And>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.PostalCode + "'/><Value Type='Text'>" + objNGODetailsEntity.PostalCode + @"</Value></Eq>
</And>
</Where>";
query.Query = strQuery;
query.ViewFields = "<FieldRef Name='" + NGODetailsEntity.FieldsName.Title + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyName + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.Incentives + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.NGOUser + @"'/>";
SPListItemCollection itemCollection = oList.GetItems(query);
//SPListItemCollection itemCollection = oList.GetItems(oQuery);
//Get collection data and add it with entity classes
if (itemCollection != null && itemCollection.Count > 0)
{
objNGO = new List<NGODetailsEntity>();
NGODetailsEntity objNGONew = null;
for (int i = 0; i < itemCollection.Count; i++)
{
objNGONew = new NGODetailsEntity();
objNGONew.Title = itemCollection[i][NGODetailsEntity.FieldsName.Title].GetString();
objNGONew.CompanyName = itemCollection[i][NGODetailsEntity.FieldsName.CompanyName].GetString();
objNGONew.NGOUser = itemCollection[i][NGODetailsEntity.FieldsName.NGOUser].GetBoolean();
objNGO.Add(objNGONew);
}
}
}
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return objNGO;
}
public static int AddNGODetails(NGODetailsEntity objNGODetailsEntity)
{
int success = 0;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
web.AllowUnsafeUpdates = true;
SPList oList = web.Lists[NGODetailsEntity.ListName];
if (oList != null)
{
//Add a new item in the List
SPListItem item = oList.Items.Add();
item[NGODetailsEntity.FieldsName.Title] = objNGODetailsEntity.Title;
item[NGODetailsEntity.FieldsName.Email] = objNGODetailsEntity.Email;
item[NGODetailsEntity.FieldsName.Incentives] = objNGODetailsEntity.Incentives;
item[NGODetailsEntity.FieldsName.NGOUser] = objNGODetailsEntity.NGOUser;
item.Update();
success = 1;
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return success;
}
public static int UpdateNGODetails(NGODetailsEntity objNGODetailsEntity)
{
int success = 0;
try
{
string strQuery = @"<Where>
<And>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.SAPId + "'/><Value Type='Text'>" + objNGODetailsEntity.SAPId + @"</Value></Eq>
</And>
</Where>";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// create the site object
using (SPSite site = new SPSite(Common.NGOSitePath))
{
// create the web object
using (SPWeb web = site.OpenWeb("ngo"))
{
web.AllowUnsafeUpdates = true;
SPQuery query = new SPQuery();
query.Query = strQuery;
// create the list object
SPList oList = web.Lists[NGODetailsEntity.ListName];
//create the item collection object
SPListItemCollection itemcollection = oList.GetItems(query);
foreach (SPListItem item in itemcollection)
{
SPListItem itemToUpdate = oList.GetItemById(item.ID);
itemToUpdate[NGODetailsEntity.FieldsName.Title] = objNGODetailsEntity.Title;
itemToUpdate[NGODetailsEntity.FieldsName.NGOUser] = objNGODetailsEntity.NGOUser;
// updating the data
itemToUpdate.Update();
success = 1;
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return success;
}
}
{
public static NGODetailsEntity GetNGODetailsById(string Id)
{
NGODetailsEntity objNGO = null;
try
{
string strQuery = @"<Where>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.SAPId + "'/><Value Type='Text'>" + Id + @"</Value></Eq>
</Where>";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
QueryBuilder queryBuilder = new QueryBuilder();
queryBuilder.QueryString = strQuery;
queryBuilder.ViewFields = "<FieldRef Name='" + NGODetailsEntity.FieldsName.Title + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyName + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.Country + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.Incentives + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.NGOUser + @"'/>";
SPQuery oQuery = Queries.GetSPQuery(queryBuilder);
SPList oList = web.Lists[NGODetailsEntity.ListName];
if (oList != null && oList.ItemCount > 0)
{
SPListItemCollection itemCollection = oList.GetItems(oQuery);
//Get collection data and add it with entity classes
if (itemCollection != null && itemCollection.Count > 0)
{
SPListItem item = itemCollection[0];
objNGO = new NGODetailsEntity();
objNGO.Title = item[NGODetailsEntity.FieldsName.Title].GetString();
objNGO.CompanyName = item[NGODetailsEntity.FieldsName.CompanyName].GetString();
objNGO.Incentives = item[NGODetailsEntity.FieldsName.Incentives].GetBoolean();
objNGO.NGOUser = item[NGODetailsEntity.FieldsName.NGOUser].GetBoolean();
}
}
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return objNGO;
}
public static List<NGODetailsEntity> GetActiveNGODetail()
{
List<NGODetailsEntity> objNGO = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
SPList oList = web.Lists[NGODetailsEntity.ListName];
if (oList != null && oList.ItemCount > 0)
{
SPQuery query = new SPQuery();
query.ViewFields = "<FieldRef Name='" + NGODetailsEntity.FieldsName.Title + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyName + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyType + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.NGOUser + @"'/>";
SPListItemCollection itemCollection = oList.GetItems(query);
//Get collection data and add it with entity classes
if (itemCollection != null && itemCollection.Count > 0)
{
objNGO = new List<NGODetailsEntity>();
NGODetailsEntity objNGONew = null;
for (int i = 0; i < itemCollection.Count; i++)
{
objNGONew = new NGODetailsEntity();
objNGONew.Title = itemCollection[i][NGODetailsEntity.FieldsName.Title].GetString();
objNGONew.Country = itemCollection[i][NGODetailsEntity.FieldsName.Country].GetString();
objNGONew.Incentives = itemCollection[i][NGODetailsEntity.FieldsName.Incentives].GetBoolean();
objNGONew.NGOUser = itemCollection[i][NGODetailsEntity.FieldsName.NGOUser].GetBoolean();
objNGO.Add(objNGONew);
}
}
}
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return objNGO;
}
public static List<UnverifiedNGOEntity> GetInActiveNGODetail()
{
List<UnverifiedNGOEntity> objUnverifiedNGO = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
SPList oList = web.Lists[UnverifiedNGOEntity.ListName];
if (oList != null && oList.ItemCount > 0)
{
SPQuery query = new SPQuery();
string strQuery = @"<OrderBy><FieldRef Name='" + UnverifiedNGOEntity.FieldsName.Title + @"' Ascending='False' /></OrderBy>";
query.ViewFields = "<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.Title + @"'/>
<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.CompanyType + @"'/>
<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.Country + @"'/>
<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.UserName + @"'/>
<FieldRef Name='" + UnverifiedNGOEntity.FieldsName.UserDisplayName + @"'/> ";
SPListItemCollection itemCollection = oList.GetItems(query);
//Get collection data and add it with entity classes
if (itemCollection != null && itemCollection.Count > 0)
{
objUnverifiedNGO = new List<UnverifiedNGOEntity>();
UnverifiedNGOEntity objUnverifiedNGONew = null;
for (int i = 0; i < itemCollection.Count; i++)
{
objUnverifiedNGONew = new UnverifiedNGOEntity();
objUnverifiedNGONew.Title = itemCollection[i][UnverifiedNGOEntity.FieldsName.Title].GetString();
objUnverifiedNGONew.Title = itemCollection[i][UnverifiedNGOEntity.FieldsName.Title].GetString();
objUnverifiedNGONew.UserDisplayName = itemCollection[i][UnverifiedNGOEntity.FieldsName.UserDisplayName].GetString();
objUnverifiedNGO.Add(objUnverifiedNGONew);
}
}
}
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return objUnverifiedNGO;
}
public static List<NGODetailsEntity> GetFilterNGODetail(NGODetailsEntity objNGODetailsEntity)
{
List<NGODetailsEntity> objNGO = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
SPList oList = web.Lists[NGODetailsEntity.ListName];
if (oList != null && oList.ItemCount > 0)
{
SPQuery query = new SPQuery();
///caml query
///
string strQuery = @"<Where>
<And>
<And>
<And>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyName + "'/><Value Type='Text'>" + objNGODetailsEntity.CompanyName + @"</Value></Eq>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.State + "'/><Value Type='Text'>" + objNGODetailsEntity.State + @"</Value></Eq>
</And>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.Country + "'/><Value Type='Text'>" + objNGODetailsEntity.Country + @"</Value></Eq>
</And>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.PostalCode + "'/><Value Type='Text'>" + objNGODetailsEntity.PostalCode + @"</Value></Eq>
</And>
</Where>";
query.Query = strQuery;
query.ViewFields = "<FieldRef Name='" + NGODetailsEntity.FieldsName.Title + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.CompanyName + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.Incentives + @"'/>
<FieldRef Name='" + NGODetailsEntity.FieldsName.NGOUser + @"'/>";
SPListItemCollection itemCollection = oList.GetItems(query);
//SPListItemCollection itemCollection = oList.GetItems(oQuery);
//Get collection data and add it with entity classes
if (itemCollection != null && itemCollection.Count > 0)
{
objNGO = new List<NGODetailsEntity>();
NGODetailsEntity objNGONew = null;
for (int i = 0; i < itemCollection.Count; i++)
{
objNGONew = new NGODetailsEntity();
objNGONew.Title = itemCollection[i][NGODetailsEntity.FieldsName.Title].GetString();
objNGONew.CompanyName = itemCollection[i][NGODetailsEntity.FieldsName.CompanyName].GetString();
objNGONew.NGOUser = itemCollection[i][NGODetailsEntity.FieldsName.NGOUser].GetBoolean();
objNGO.Add(objNGONew);
}
}
}
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return objNGO;
}
public static int AddNGODetails(NGODetailsEntity objNGODetailsEntity)
{
int success = 0;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(Common.NGOSitePath))
{
using (SPWeb web = site.OpenWeb("ngo"))
{
web.AllowUnsafeUpdates = true;
SPList oList = web.Lists[NGODetailsEntity.ListName];
if (oList != null)
{
//Add a new item in the List
SPListItem item = oList.Items.Add();
item[NGODetailsEntity.FieldsName.Title] = objNGODetailsEntity.Title;
item[NGODetailsEntity.FieldsName.Email] = objNGODetailsEntity.Email;
item[NGODetailsEntity.FieldsName.Incentives] = objNGODetailsEntity.Incentives;
item[NGODetailsEntity.FieldsName.NGOUser] = objNGODetailsEntity.NGOUser;
item.Update();
success = 1;
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return success;
}
public static int UpdateNGODetails(NGODetailsEntity objNGODetailsEntity)
{
int success = 0;
try
{
string strQuery = @"<Where>
<And>
<Eq><FieldRef Name='" + NGODetailsEntity.FieldsName.SAPId + "'/><Value Type='Text'>" + objNGODetailsEntity.SAPId + @"</Value></Eq>
</And>
</Where>";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// create the site object
using (SPSite site = new SPSite(Common.NGOSitePath))
{
// create the web object
using (SPWeb web = site.OpenWeb("ngo"))
{
web.AllowUnsafeUpdates = true;
SPQuery query = new SPQuery();
query.Query = strQuery;
// create the list object
SPList oList = web.Lists[NGODetailsEntity.ListName];
//create the item collection object
SPListItemCollection itemcollection = oList.GetItems(query);
foreach (SPListItem item in itemcollection)
{
SPListItem itemToUpdate = oList.GetItemById(item.ID);
itemToUpdate[NGODetailsEntity.FieldsName.Title] = objNGODetailsEntity.Title;
itemToUpdate[NGODetailsEntity.FieldsName.NGOUser] = objNGODetailsEntity.NGOUser;
// updating the data
itemToUpdate.Update();
success = 1;
}
web.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
ErrorLog.LogError(ex);
}
return success;
}
}
No comments:
Post a Comment