Skip to content

Instantly share code, notes, and snippets.

@svallory
Created August 30, 2013 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svallory/6393776 to your computer and use it in GitHub Desktop.
Save svallory/6393776 to your computer and use it in GitHub Desktop.
namespace Sparrow.Domain.ServiceOrder
{
using System;
using System.Collections.Generic;
using Iesi.Collections.Generic;
using Jack.Core.Domain;
using Jack.Core.Envent;
using Sparrow.Domain.Projects;
using System.Linq;
public class ServiceOrder : IAggregateRoot
{
private readonly ProposalVersionService service;
/// <summary>
/// Files uploaded to this SO.
/// </summary>
private IDictionary<FileId, File> files;
/// <summary>
/// The phases of this SO.
/// </summary>
private Iesi.Collections.Generic.ISet<Phase> phases;
/// <summary>
/// All the extra costs of this SO's execution.
/// </summary>
private Iesi.Collections.Generic.ISet<Expense> expenses;
/// <summary>
/// The time entries of this timesheet.
/// </summary>
private Iesi.Collections.Generic.ISet<TimesheetEntry> timesheet;
public ServiceOrder(ProposalVersionService service)
{
this.service = service;
this.files = new Dictionary<FileId, File>();
this.phases = new HashedSet<Phase>();
this.expenses = new HashedSet<Expense>();
this.timesheet = new HashedSet<TimesheetEntry>();
}
/// <summary>
/// Adds a new <see cref="Phase"/> to this SO.
/// </summary>
public void AddPhase(Phase phase)
{
this.phases.Add(phase);
}
#region Timesheet
/// <summary>
/// Adds a new <see cref="TimesheetEntry"/> to this timesheet.
/// </summary>
public void AddTimeEntry(DateTime day, decimal hours, int employeeId)
{
var entry = new TimesheetEntry(day, hours, employeeId);
this.timesheet.Add(entry);
}
/// <summary>
/// Removes the specified <see cref="TimesheetEntry"/> from this timesheet.
/// </summary>
public bool RemoveTimeEntry(TimesheetEntry entry)
{
return this.timesheet.Contains(entry) && this.timesheet.Remove(entry);
}
#endregion
#region Expenses
/// <summary>
/// Adds a new <see cref="Expense"/> to this SO.
/// </summary>
public void AddExpense(Expense expense)
{
expenses.Add(expense);
}
/// <summary>
/// Removes an <see cref="Expense"/> from this SO.
/// </summary>
public bool RemoveExpense(Expense expense)
{
return expenses.Contains(expense) && expenses.Remove(expense);
}
#endregion
/// <summary>
/// Adds a new uploaded file to this ServiceOrder.
/// </summary>
public void AddFile(string name, byte[] data)
{
var file = new File(name, data);
files.Add(file.Id, file);
}
/// <summary>
/// Updates a file with a new document version.
/// </summary>
public void UpdateFile(FileId fileId, byte[] data)
{
if (!this.files.ContainsKey(fileId))
throw new Exception("The file you are trying to update does not exist.");
this.files[fileId].AddVersion(data);
}
/// <summary>
/// Removes a file from this ServiceOrder.
/// </summary>
public File RemoveFile(FileId fileId)
{
if (files.ContainsKey(fileId))
{
var file = files[fileId];
files.Remove(fileId);
return file;
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment