|
using System;
using System.Linq;
namespace DateSite
{
/// <summary>
/// Data layer for CRUD operations.
/// </summary>
public class Database
{
/// <summary>
/// Returns the set of all corresponding pairs of Dating IDs and
/// navigational Workflow IDs from database.
/// </summary>
/// <returns></returns>
public static object GetExistingProfiles()
{
ProfileDataContext context = new ProfileDataContext();
var workflows = from p in context.Profiles select new { p.DatingId, p.WorkflowId };
var resultSet = workflows.ToList();
context.Dispose();
return resultSet;
}
/// <summary>
/// Inserts the given profile into the database.
/// </summary>
/// <param name="profile"></param>
public static void InsertProfile(Profile profile)
{
// insert the given profile into the database
ProfileDataContext context = new ProfileDataContext();
context.Profiles.InsertOnSubmit(profile);
context.SubmitChanges();
context.Dispose();
}
/// <summary>
/// Takes the information in the given profile and updates the
/// corresponding record in the database.
/// </summary>
/// <param name="profile"></param>
public static void UpdateProfile(Profile profile)
{
// update the given profile
ProfileDataContext context = new ProfileDataContext();
context.Profiles.Attach(profile, true);
context.SubmitChanges();
context.Dispose();
}
/// <summary>
/// Returns the profile object with the given dating id from the database.
/// </summary>
/// <param name="datingId"></param>
/// <returns></returns>
public static Profile SelectProfile(string datingId)
{
ProfileDataContext context = new ProfileDataContext();
Profile profile = (from p in context.Profiles where p.DatingId.Equals(datingId) select p).First();
context.Dispose();
return profile;
}
/// <summary>
/// Deletes the given dating id and workflow id records from the database.
/// </summary>
/// <param name="datingId"></param>
/// <param name="workflowId"></param>
public static void DeleteProfile(string datingId, Guid workflowId)
{
ProfileDataContext context = new ProfileDataContext();
// delete the profile record
var profile = from p in context.Profiles where p.DatingId.Equals(datingId) select p;
context.Profiles.DeleteAllOnSubmit(profile);
// delete the workflow record
var workflow = from i in context.InstanceStates where i.uidInstanceID.Equals(workflowId) select i;
context.InstanceStates.DeleteAllOnSubmit(workflow);
// submit the changes and dispose of the context object
context.SubmitChanges();
context.Dispose();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.