protected override IAggregateFluent <EmployeeView> ConvertToViewAggreagate(IAggregateFluent <Employee> mappings, IExpressionContext <Employee, EmployeeView> context) { var afState = @"{ ""$addFields"": { ""has_user"": { ""$cond"": [ { ""$ne"": [""$user"", undefined ] }, true, false ] }, ""username"": ""$user.username"", ""permission"": { ""$cond"": [ { ""$ne"": [""$user.permission"", undefined ] }, ""$user.permission"", 0 ] } } }"; var pjState = @"{ ""user"": 0 }"; var unwind = new AggregateUnwindOptions <BsonDocument> { PreserveNullAndEmptyArrays = true }; return(mappings .Lookup("user", "_id", "code", "user").Unwind("user", unwind) .Lookup("facutly", "facutly_code", "_id", "facutly").Unwind("facutly", unwind) .Lookup("level", "level_code", "_id", "level").Unwind("level", unwind) .Lookup("major", "major_code", "_id", "major").Unwind("major", unwind) .AppendStage <BsonDocument>(BsonDocument.Parse(afState)) .Project(BsonDocument.Parse(pjState)) .As <EmployeeView>() .Match(context.GetPostExpression())); }
protected override IAggregateFluent <EmployeeView> ConvertToViewAggreagate(IAggregateFluent <Employee> mappings, IExpressionContext <Employee, EmployeeView> context) { var afState = @"{ ""$addFields"": { ""has_user"": { ""$cond"": [{ ""$ne"": [ ""$user"", undefined ] }, true, false ] }, ""username"": ""$user.username"", ""uermission"": ""$user.uermission"" } }"; var pjState = @"{ ""User"": 0 }"; var unwind = new AggregateUnwindOptions <BsonDocument> { PreserveNullAndEmptyArrays = true }; // TODO: Mapping them JobPosition + Department + JobTitle return(mappings .Lookup("user", "user_code", "code", "user").Unwind("user", unwind) .Lookup("job_position", "job_position_code", "code", "job_position").Unwind("job_position", unwind) .Lookup("department", "job_position.department_code", "code", "department").Unwind("department", unwind) .Lookup("job_title", "job_position.job_title_code", "code", "job_title").Unwind("job_title", unwind) .AppendStage <BsonDocument>(BsonDocument.Parse(afState)) .Project(BsonDocument.Parse(pjState)) .As <EmployeeView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <CustomerView> ConvertToViewAggreagate(IAggregateFluent <Customer> mappings, IExpressionContext <Customer, CustomerView> context) { var unwind = new AggregateUnwindOptions <CustomerView> { PreserveNullAndEmptyArrays = true }; return(mappings.Lookup("employee", "employee_code", "code", "employee").Unwind("employee", unwind) .As <CustomerView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <MaterialReceivingVoucherView> ConvertToViewAggreagate(IAggregateFluent <MaterialReceivingVoucher> mappings, IExpressionContext <MaterialReceivingVoucher, MaterialReceivingVoucherView> context) { var unwind = new AggregateUnwindOptions <MaterialReceivingVoucher> { PreserveNullAndEmptyArrays = true }; var group = @" { _id: { _id : ""$_id"", code : ""$Code"", def_code : ""$DefCode"", name : ""$name"", value_to_search : ""$value_to_search"", is_published : ""$is_published"", created_date : ""$created_date"", last_modified : ""$last_modified"", delivery_code: ""$delivery_code"", supplier_code: ""$supplier_code"", category : ""$category"", description: ""$description"", document_date : ""$document_date"" }, infos: { ""$addToSet"": ""$infos"" } }"; var projection = @" { _id : ""$_id._id"", code : ""$_id.Code"", def_code : ""$_id.DefCode"", name : ""$_id.name"", value_to_search : ""$_id.value_to_search"", is_published : ""$_id.is_published"", created_date : ""$_id.created_date"", last_modified : ""$_id.last_modified"", delivery_code: ""$_id.delivery_code"", supplier_code: ""$_id.supplier_code"", category : ""$_id.category"", description: ""$_id.description"", document_date : ""$_id.document_date"" infos: ""infos"" }"; return(mappings .Unwind("infos", unwind) .Lookup("material", "infos.code", "code", "infos.store.material") .Unwind("infos.store.material", unwind) .Lookup("material_group", "infos.store.material.material_group_code", "code", "infos.store.material_group") .Unwind("infos.store.material_group", unwind) .Lookup("material_subgroup", "infos.store.material.material_subgroup_code", "code", "infos.store.material_subgroup") .Unwind("infos.store.material_subgroup", unwind) .Group(BsonDocument.Parse(group)) .Project(BsonDocument.Parse(projection)) .Lookup("supplier", "supplier_code", "code", "supplier") .Unwind("supplier", unwind) .As <MaterialReceivingVoucherView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <MaterialGroupTypeView> ConvertToViewAggreagate(IAggregateFluent <MaterialGroupType> mappings, IExpressionContext <MaterialGroupType, MaterialGroupTypeView> context) { var unwind = new AggregateUnwindOptions <BsonDocument> { PreserveNullAndEmptyArrays = true }; return(mappings.Lookup("material_group", "material_group_code", "code", "material_group").Unwind("material_group") .Lookup("material_subgroup", "material_sub_group_code", "code", "material_subgroup").Unwind("material_subgroup") .As <MaterialGroupTypeView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <DepartmentView> ConvertToViewAggreagate(IAggregateFluent <Department> mappings, IExpressionContext <Department, DepartmentView> context) { var unwind = new AggregateUnwindOptions <DepartmentView> { PreserveNullAndEmptyArrays = true }; return(mappings.Lookup("department", "parent_code", "code", "parent") .Unwind("parent", unwind) .As <DepartmentView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <ProductView> ConvertToViewAggreagate(IAggregateFluent <Product> mappings, IExpressionContext <Product, ProductView> context) { var unwind = new AggregateUnwindOptions <ProductView> { PreserveNullAndEmptyArrays = true }; return(mappings.Lookup("product_group", "product_group_code", "code", "product_group").Unwind("product_group", unwind) .Lookup("product_subgroup", "product_subgroup_code", "code", "product_subgroup").Unwind("product_subgroup", unwind) .As <ProductView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <StudentView> ConvertToViewAggreagate(IAggregateFluent <Student> mappings, IExpressionContext <Student, StudentView> context) { var unwind = new AggregateUnwindOptions <BsonDocument> { PreserveNullAndEmptyArrays = true }; return(mappings.Lookup("center", "center_code", "_id", "center").Unwind("center", unwind) .Lookup("major", "major_code", "_id", "major").Unwind("major", unwind) .Lookup("classroom", "classroom_code", "_id", "classroom").Unwind("classroom", unwind) .As <StudentView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <EmployeeCourseView> ConvertToViewAggreagate(IAggregateFluent <EmployeeCourse> mappings, IExpressionContext <EmployeeCourse, EmployeeCourseView> context) { var unwind = new AggregateUnwindOptions <BsonDocument> { PreserveNullAndEmptyArrays = true }; return(mappings.Lookup("employee", "employee_code", "_id", "employee").Unwind("employee", unwind) .Lookup("course", "course_code", "_id", "course").Unwind("course", unwind) .Lookup("facutly", "facutly_code", "_id", "facutly").Unwind("facutly", unwind) .Lookup("major", "major_code", "_id", "major").Unwind("major", unwind) .As <EmployeeCourseView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <WarehouseInventoryView> ConvertToViewAggreagate(IAggregateFluent <WarehouseInventory> mappings, IExpressionContext <WarehouseInventory, WarehouseInventoryView> context) { var unwind = new AggregateUnwindOptions <BsonDocument> { PreserveNullAndEmptyArrays = true }; return(mappings.Lookup("warehouse", "warehouse_code", "code", "warehouse").Unwind("warehouse", unwind) .Lookup("material", "material_code", "code", "material").Unwind("material", unwind) .Lookup("material_group", "material_group_code", "code", "material_group").Unwind("material_group", unwind) .Lookup("material_subgroup", "material_sub_group_code", "code", "material_sub_group").Unwind("material_sub_group", unwind) .Lookup("material_group_type", "material_group_type_code", "code", "material_group_type").Unwind("material_group_type", unwind) .Lookup("unit", "unit_code", "code", "unit").Unwind("unit", unwind) .As <WarehouseInventoryView>().Match(context.GetPostExpression())); }
protected override IAggregateFluent <MaterialDeliveryVoucherView> ConvertToViewAggreagate(IAggregateFluent <MaterialDeliveryVoucher> mappings, IExpressionContext <MaterialDeliveryVoucher, MaterialDeliveryVoucherView> context) { var unwind = new AggregateUnwindOptions <MaterialDeliveryVoucher> { PreserveNullAndEmptyArrays = true }; var group = @" { _id: { _id : ""$_id"", code : ""$Code"", def_code : ""$DefCode"", name : ""$name"", value_to_search : ""$value_to_search"", is_published : ""$is_published"", created_date : ""$created_date"", last_modified : ""$last_modified"", delivery_type: ""$delivery_type"", other_type: ""$other_type"", customer_code : ""$customer_code"", other_customer_code : ""$other_customer_code"", supplier_code : ""$supplier_code"", invoice_code : ""$invoice_code"", reason : ""$reason"", description: ""$description"", document_date : ""$document_date"" }, infos: { ""$addToSet"": ""$infos"" } }"; var projection = @" { _id: ""$_id._id"", code: ""$_id.code"", def_code: ""$_id.def_code"", name : ""$_id.name"", delivery_type: ""$_id.delivery_type"", other_type: ""$_id.other_type"", description: ""$_id.description"", value_to_search: ""$_id.value_to_search"", is_published: ""$_id.is_published"", created_date: ""$_id.created_date"", last_modified: ""$_id.last_modified"", customer_code : ""$_id.customer_code"", other_customer_code : ""$_id.other_customer_code"", supplier_code : ""$_id.supplier_code"", invoice_code : ""$_id.invoice_code"", reason : ""$_id.reason"", document_date: ""$_id.document_date"", infos: ""infos"" }"; var projection_store = @" { ""delivery"": 0, ""infos.store.material.receiving"": 0, ""infos.store.material.material_group"": 0, ""infos.store.material.material_subgroup"": 0 }"; var append_receivingmap = @" { $addFields: { ""receiving_map"": { $concat: [ ""$infos.receiving_code"", ""_"", ""$infos.code"" ] } } }"; var append_store = @" { $addFields: { ""infos.store.material"": ""$delivery"", ""infos.store.material_group"": ""$delivery.material_group"", ""infos.store.material_subgroup"": ""$delivery.material_subgroup"", ""infos.store.inventory"": ""$delivery.inventory"", ""infos.store.price"": ""$delivery.Price"", ""infos.store.receiving"": ""$delivery.receiving"", ""infos.store.last"": ""$Infos.quantity"" } }"; return(mappings .Unwind("infos", unwind) .AppendStage <BsonDocument>(BsonDocument.Parse(append_receivingmap)) .Lookup("material_for_delivery_view", "receiving_map", "receiving_map", "delivery") .Unwind("delivery", unwind) .AppendStage <BsonDocument>(BsonDocument.Parse(append_store)) .Project(BsonDocument.Parse(projection_store)) .Group(BsonDocument.Parse(group)) .Project(BsonDocument.Parse(projection)) .Lookup("customer", "customer_code", "code", "customer") .Unwind("customer", unwind) .Lookup("customer", "other_customer_code", "code", "other_customer") .Unwind("other_customer", unwind) .Lookup("supplier", "supplier_code", "code", "supplier") .Unwind("supplier", unwind) .As <MaterialDeliveryVoucherView>().Match(context.GetPostExpression())); }