public void UpdateAssignment(ExecutionContextInfo context, Assignment assignment)
        {
            if (assignment == null)
            {
                throw new ArgumentNullException("assignment");
            }

            if (assignment.Identifier == Guid.Empty)
            {
                throw new ArgumentNullException("Assignment.Identifier");
            }

            using (var ctx = new Server.System.Repository.DataAccess.CaseHandlingDatabaseContext())
            {
                var assignmentEntity = (from c in ctx.AssignmentEntities where c.ID == assignment.Identifier select c).FirstOrDefault();
                if (assignmentEntity == null)
                {
                    throw new CaseHandlingException(string.Format("Assignment ({0}) information not found provided by Workflow ({1})", assignment.Identifier, assignment.FlowInstanceIdentifier));
                }
                var ca = assignmentEntity;
                ca.Accepted       = assignment.Accepted;
                ca.Assigned       = assignment.Assigned;
                ca.Active         = assignment.Active;
                ca.FlowInstanceID = assignment.FlowInstanceIdentifier;
                ctx.SaveChanges();
            }
        }
        public Officer CreateOfficer(Officer officer)
        {
            using (var ctx = new Server.System.Repository.DataAccess.CaseHandlingDatabaseContext())
            {
                OfficerEntity manager = null;
                if (officer.Manager != null)
                {
                    manager = (from m in ctx.OfficerEntities
                               where m.ID == officer.Manager.Identifier
                               select m).First();
                }
                var off = new OfficerEntity()
                {
                    ID      = Guid.NewGuid(),
                    Manager = manager,
                    Name    = officer.Name,
                    Role    = officer.Role,
                };
                ctx.OfficerEntities.AddObject(off);
                ctx.SaveChanges();

                officer.Identifier = off.ID;
                return(officer);
            }
        }
        public IEnumerable <Officer> ListOfficers()
        {
            var list = new List <Officer>();

            using (var ctx = new Server.System.Repository.DataAccess.CaseHandlingDatabaseContext())
            {
                var staffs = (from m in ctx.OfficerEntities
                              select m).ToList();
                Fill(list, staffs);
            }

            return(list);
        }
        public IEnumerable <CaseInfo> ListCases()
        {
            var list = new List <CaseInfo>();

            using (var ctx = new Server.System.Repository.DataAccess.CaseHandlingDatabaseContext())
            {
                var result = (from c in ctx.CaseEntities
                              select c).ToList();

                foreach (var c in result)
                {
                    list.Add(EntityConvertorUtility.ConvertCaseInfo(c));
                }
            }
            return(list);
        }
        public Assignment CreateAssignment(ExecutionContextInfo context, Assignment assignment)
        {
            if (assignment == null)
            {
                throw new ArgumentNullException("assignment");
            }

            if (assignment.Case == null || assignment.Case.Identifier == Guid.Empty)
            {
                throw new ArgumentNullException("Assignment.Case.Identifier");
            }

            if (assignment.Officer == null || assignment.Officer.Identifier == Guid.Empty)
            {
                throw new ArgumentNullException("Assignment.Officer.Identifier");
            }

            if (assignment.Assigned == null)
            {
                assignment.Assigned = DateTime.Now;
            }

            using (var ctx = new Server.System.Repository.DataAccess.CaseHandlingDatabaseContext())
            {
                var caseEntity    = (from ca in ctx.CaseEntities where ca.ID == assignment.Case.Identifier select ca).FirstOrDefault();
                var officerEntity = (from of in ctx.OfficerEntities where of.ID == assignment.Officer.Identifier select of).FirstOrDefault();
                if (caseEntity == null || officerEntity == null)
                {
                    throw new CaseHandlingException(string.Format("Case ({0}) or Officer ({1}) information not found provided by Workflow ({2})", assignment.Case.Identifier, assignment.Officer.Identifier, assignment.FlowInstanceIdentifier));
                }
                var c = new AssignmentEntity()
                {
                    ID             = Guid.NewGuid(),
                    Case           = caseEntity,
                    Officer        = officerEntity,
                    Active         = true,
                    Assigned       = assignment.Assigned,
                    FlowInstanceID = assignment.FlowInstanceIdentifier,
                };
                ctx.AssignmentEntities.AddObject(c);
                ctx.SaveChanges();
                assignment.Active     = c.Active;
                assignment.Identifier = c.ID;

                return(assignment);
            }
        }
 public CaseInfo CreateCase(CaseInfo caseInfo)
 {
     using (var ctx = new Server.System.Repository.DataAccess.CaseHandlingDatabaseContext())
     {
         if (caseInfo.Created == null)
         {
             caseInfo.Created = DateTime.Now;
         }
         var c = new CaseEntity()
         {
             ID          = Guid.NewGuid(),
             Description = caseInfo.Description,
             Task        = caseInfo.Task,
             ClientEmail = caseInfo.ClientAddress
         };
         c.Created = caseInfo.Created.Value;
         ctx.CaseEntities.AddObject(c);
         ctx.SaveChanges();
         caseInfo.Identifier = c.ID;
         return(caseInfo);
     }
 }