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);
            }
        }
Ejemplo n.º 2
0
 static internal Officer ConvertOfficer(OfficerEntity officer)
 {
     return(new Officer()
     {
         Identifier = officer.ID,
         Role = officer.Role,
         Name = officer.Name,
         Manager = null,
         Subordinate = new List <Officer>()
     });
 }
        private Officer GetManager(List <OfficerEntity> staffs, OfficerEntity stf)
        {
            if (stf.Manager == null)
            {
                return(null);
            }
            var mng     = stf.Manager;
            var officer = EntityConvertorUtility.ConvertOfficer(mng);

            return(officer);
        }
        public IEnumerable <Assignment> ListAssignments(bool withDetail)
        {
            List <Assignment> list = new List <Assignment>();

            using (var ctx = new CaseHandlingDatabaseContext())
            {
                List <AssignmentEntity> results = (from co in ctx.AssignmentEntities select co).ToList();
                foreach (var res in results)
                {
                    var co = EntityConvertorUtility.ConvertCaseOfficer(res);
                    list.Add(co);
                    if (withDetail)
                    {
                        if (!res.CaseReference.IsLoaded)
                        {
                            res.CaseReference.Load();
                        }
                        co.Case = EntityConvertorUtility.ConvertCaseInfo(res.Case);

                        if (!res.OfficerReference.IsLoaded)
                        {
                            res.OfficerReference.Load();
                        }

                        co.Officer = EntityConvertorUtility.ConvertOfficer(res.Officer);
                        // loads the officer hierarchy to management
                        Officer       officer = co.Officer;
                        OfficerEntity oe      = res.Officer;
                        while (oe.ManagerReference != null)
                        {
                            if (!oe.ManagerReference.IsLoaded)
                            {
                                oe.ManagerReference.Load();
                            }
                            if (oe.Manager == null)
                            {
                                break;
                            }

                            officer.Manager = EntityConvertorUtility.ConvertOfficer(oe.Manager);
                            oe      = oe.Manager;
                            officer = officer.Manager;
                        }
                    }
                }
            }
            return(list);
        }