Ejemplo n.º 1
0
        // Create a new version of this object or use it from the lookup.
        public static CaseProductDtoGen Create(Coalesce.Domain.CaseProduct obj, ClaimsPrincipal user = null, string includes = null,
                                               Dictionary <object, object> objects = null, IncludeTree tree = null)
        {
            // Return null of the object is null;
            if (obj == null)
            {
                return(null);
            }

            if (objects == null)
            {
                objects = new Dictionary <object, object>();
            }

            includes = includes ?? "";

            // Applicable includes for CaseProduct


            // Applicable excludes for CaseProduct


            // Applicable roles for CaseProduct
            if (user != null)
            {
            }



            // See if the object is already created, but only if we aren't restricting by an includes tree.
            // If we do have an IncludeTree, we know the exact structure of our return data, so we don't need to worry about circular refs.
            if (tree == null && objects.ContainsKey(obj))
            {
                return((CaseProductDtoGen)objects[obj]);
            }

            var newObject = new CaseProductDtoGen();

            if (tree == null)
            {
                objects.Add(obj, newObject);
            }
            // Fill the properties of the object.
            newObject.CaseProductId = obj.CaseProductId;
            newObject.CaseId        = obj.CaseId;
            newObject.ProductId     = obj.ProductId;
            if (tree == null || tree[nameof(newObject.Case)] != null)
            {
                newObject.Case = CaseDtoGen.Create(obj.Case, user, includes, objects, tree?[nameof(newObject.Case)]);
            }

            if (tree == null || tree[nameof(newObject.Product)] != null)
            {
                newObject.Product = ProductDtoGen.Create(obj.Product, user, includes, objects, tree?[nameof(newObject.Product)]);
            }

            return(newObject);
        }
Ejemplo n.º 2
0
        // Create a new version of this object or use it from the lookup.
        public static PersonDtoGen Create(Coalesce.Domain.Person obj, ClaimsPrincipal user = null, string includes = null,
                                          Dictionary <object, object> objects = null, IncludeTree tree             = null)
        {
            // Return null of the object is null;
            if (obj == null)
            {
                return(null);
            }

            if (objects == null)
            {
                objects = new Dictionary <object, object>();
            }

            includes = includes ?? "";

            // Applicable includes for Person


            // Applicable excludes for Person


            // Applicable roles for Person
            bool isAdmin = false;

            if (user != null)
            {
                isAdmin = user.IsInRole("Admin");
            }



            // See if the object is already created, but only if we aren't restricting by an includes tree.
            // If we do have an IncludeTree, we know the exact structure of our return data, so we don't need to worry about circular refs.
            if (tree == null && objects.ContainsKey(obj))
            {
                return((PersonDtoGen)objects[obj]);
            }

            var newObject = new PersonDtoGen();

            if (tree == null)
            {
                objects.Add(obj, newObject);
            }
            // Fill the properties of the object.
            newObject.PersonId  = obj.PersonId;
            newObject.Title     = obj.Title;
            newObject.FirstName = obj.FirstName;
            newObject.LastName  = obj.LastName;
            newObject.Email     = obj.Email;
            if ((isAdmin))
            {
                newObject.Gender = obj.Gender;
            }
            newObject.BirthDate     = obj.BirthDate;
            newObject.LastBath      = obj.LastBath;
            newObject.NextUpgrade   = obj.NextUpgrade;
            newObject.PersonStatsId = obj.PersonStatsId;
            newObject.TimeZone      = obj.TimeZone;
            newObject.Name          = obj.Name;
            newObject.CompanyId     = obj.CompanyId;
            var propValCasesAssigned = obj.CasesAssigned;

            if (propValCasesAssigned != null && (tree == null || tree[nameof(newObject.CasesAssigned)] != null))
            {
                newObject.CasesAssigned = propValCasesAssigned.OrderBy("CaseKey ASC").Select(f => CaseDtoGen.Create(f, user, includes, objects, tree?[nameof(newObject.CasesAssigned)])).ToList();
            }
            else if (propValCasesAssigned == null && tree?[nameof(newObject.CasesAssigned)] != null)
            {
                newObject.CasesAssigned = new CaseDtoGen[0];
            }

            var propValCasesReported = obj.CasesReported;

            if (propValCasesReported != null && (tree == null || tree[nameof(newObject.CasesReported)] != null))
            {
                newObject.CasesReported = propValCasesReported.OrderBy("CaseKey ASC").Select(f => CaseDtoGen.Create(f, user, includes, objects, tree?[nameof(newObject.CasesReported)])).ToList();
            }
            else if (propValCasesReported == null && tree?[nameof(newObject.CasesReported)] != null)
            {
                newObject.CasesReported = new CaseDtoGen[0];
            }


            newObject.PersonStats = PersonStatsDtoGen.Create(obj.PersonStats, user, includes, objects, tree?[nameof(newObject.PersonStats)]);

            if (tree == null || tree[nameof(newObject.Company)] != null)
            {
                newObject.Company = CompanyDtoGen.Create(obj.Company, user, includes, objects, tree?[nameof(newObject.Company)]);
            }

            return(newObject);
        }