private void AssertBasicChecks(IncludeTree tree) { // Basic check to see if IncludeTree works for EF includes. Assert.NotNull(tree [nameof(Person.CasesAssigned)] [nameof(Case.CaseProducts)] [nameof(CaseProduct.Case)] [nameof(Case.AssignedTo)]); // Make sure that multiple EF include calls merge properly. // If this doesn't pass, something is wrong with the way merging is done. Assert.NotNull(tree [nameof(Person.CasesAssigned)] [nameof(Case.CaseProducts)] [nameof(CaseProduct.Case)] [nameof(Case.ReportedBy)]); // check to see if IncludedSeparately works Assert.NotNull(tree [nameof(Person.CasesReported)] [nameof(Case.ReportedBy)] [nameof(Person.Company)]); // Make sure that multiple IncludedSeprately calls merge properly. // If this doesn't pass, something is wrong with the way merging is done. Assert.NotNull(tree [nameof(Person.CasesReported)] [nameof(Case.ReportedBy)] [nameof(Person.CasesAssigned)]); }
public void MapFrom(Case obj, IMappingContext context = null, IncludeTree tree = null) { CaseId = obj.CaseKey; Title = obj.Title; if (obj.AssignedTo != null) { AssignedToName = obj.AssignedTo.Name; } }
public virtual async Task<ItemResult<WeatherDataDtoGen>> GetWeatherAsync([FromServices] Coalesce.Domain.AppDbContext parameterDbContext, LocationDtoGen location, System.DateTimeOffset? dateTime) { IncludeTree includeTree = null; var methodResult = await Service.GetWeatherAsync(parameterDbContext, location.MapToModel(new Coalesce.Domain.Services.Location(), new MappingContext(User)), dateTime); var result = new ItemResult<WeatherDataDtoGen>(); var mappingContext = new MappingContext(User, ""); result.Object = Mapper.MapToDto<Coalesce.Domain.Services.WeatherData, WeatherDataDtoGen>(methodResult, mappingContext, includeTree); return result; }
public virtual ItemResult <ICollection <CompanyDtoGen> > GetCertainItems(bool isDeleted = false) { IncludeTree includeTree = null; var methodResult = Coalesce.Domain.Company.GetCertainItems(Db, isDeleted); var result = new ItemResult <ICollection <CompanyDtoGen> >(); var mappingContext = new MappingContext(User, ""); result.Object = methodResult?.ToList().Select(o => Mapper.MapToDto <Coalesce.Domain.Company, CompanyDtoGen>(o, mappingContext, includeTree)).ToList(); return(result); }
public virtual ItemResult <WeatherDataDtoGen> GetWeather([FromServices] Coalesce.Domain.AppDbContext parameterDbContext, LocationDtoGen location) { IncludeTree includeTree = null; var methodResult = Service.GetWeather(parameterDbContext, location.MapToModel(new Coalesce.Domain.Services.Location(), new MappingContext(User))); var result = new ItemResult <WeatherDataDtoGen>(); var mappingContext = new MappingContext(User, ""); result.Object = Mapper.MapToDto <Coalesce.Domain.Services.WeatherData, WeatherDataDtoGen>(methodResult, mappingContext, includeTree); return(result); }
public virtual ItemResult <ICollection <CaseDtoGen> > GetSomeCases() { IncludeTree includeTree = null; var methodResult = Coalesce.Domain.Case.GetSomeCases(Db); var result = new ItemResult <ICollection <CaseDtoGen> >(); var mappingContext = new MappingContext(User, ""); result.Object = methodResult?.ToList().Select(o => Mapper.MapToDto <Coalesce.Domain.Case, CaseDtoGen>(o, mappingContext, includeTree)).ToList(); return(result); }
public virtual ListResult <PersonDtoGen> SearchPeople(PersonCriteriaDtoGen criteria, int page) { IncludeTree includeTree = null; var methodResult = Coalesce.Domain.Person.SearchPeople(Db, criteria.MapToModel(new Coalesce.Domain.PersonCriteria(), new MappingContext(User)), page); var result = new ListResult <PersonDtoGen>(methodResult); var mappingContext = new MappingContext(User, ""); result.List = methodResult.List?.ToList().Select(o => Mapper.MapToDto <Coalesce.Domain.Person, PersonDtoGen>(o, mappingContext, includeTree)).ToList(); return(result); }
public virtual ItemResult <ICollection <PersonDtoGen> > FilterPeople(string filter) { IncludeTree includeTree = null; var methodResult = CoalescePlayground.Data.Models.Person.FilterPeople(Db, filter); var result = new ItemResult <ICollection <PersonDtoGen> >(); var mappingContext = new MappingContext(User, ""); result.Object = methodResult?.ToList().Select(o => Mapper.MapToDto <CoalescePlayground.Data.Models.Person, PersonDtoGen>(o, mappingContext, includeTree)).ToList(); return(result); }
public virtual ItemResult <CaseSummaryDtoGen> GetCaseSummary() { IncludeTree includeTree = null; var methodResult = Coalesce.Domain.Case.GetCaseSummary(Db); var result = new ItemResult <CaseSummaryDtoGen>(); var mappingContext = new MappingContext(User, ""); result.Object = Mapper.MapToDto <Coalesce.Domain.CaseSummary, CaseSummaryDtoGen>(methodResult, mappingContext, includeTree); return(result); }
public virtual ItemResult <TriviaBoardDtoGen> GetTriviaBoardOfId(int id) { IncludeTree includeTree = null; var methodResult = Service.GetTriviaBoardOfId(id); var result = new ItemResult <TriviaBoardDtoGen>(); var mappingContext = new MappingContext(User, ""); result.Object = Mapper.MapToDto <TriviaGame.Data.Models.TriviaBoard, TriviaBoardDtoGen>(methodResult, mappingContext, includeTree); return(result); }
// Create a new version of this object or use it from the lookup. public static BlogDtoGen Create(Coalesce.TaskListSample.Data.Models.Blog 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 Blog // Applicable excludes for Blog // Applicable roles for Blog 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((BlogDtoGen)objects[obj]); } var newObject = new BlogDtoGen(); if (tree == null) { objects.Add(obj, newObject); } // Fill the properties of the object. newObject.BlogId = obj.BlogId; newObject.Name = obj.Name; newObject.Url = obj.Url; newObject.AuthorId = obj.AuthorId; if (tree == null || tree[nameof(newObject.Author)] != null) { newObject.Author = AuthorDtoGen.Create(obj.Author, user, includes, objects, tree?[nameof(newObject.Author)]); } return(newObject); }
public virtual SaveResult <IEnumerable <CaseDtoGen> > GetAllOpenCases() { var result = new SaveResult <IEnumerable <CaseDtoGen> >(); try{ IncludeTree includeTree = null; var objResult = Coalesce.Domain.Case.GetAllOpenCases(Db); result.Object = objResult.ToList().Select(o => Mapper <Coalesce.Domain.Case, CaseDtoGen> .ObjToDtoMapper(o, User, "", (objResult as IQueryable)?.GetIncludeTree() ?? includeTree)); result.WasSuccessful = true; result.Message = null; }catch (Exception ex) { result.WasSuccessful = false; result.Message = ex.Message; } return(result); }
public static IncludeTree[] Build(string include, Type resposeType, Type modelType, Expression parameter) { string[][] includesArray = include.Split(',').Select(x => x.Split('.')).ToArray(); Dictionary <string, IncludeTree> dic = new Dictionary <string, IncludeTree>(); for (int i = 0; i < includesArray.Length; i++) { IncludeTree incTree = null; for (int j = 0; j < includesArray[i].Length; j++) { var propertyName = includesArray[i][j]; if (j == 0) { if (!dic.TryGetValue(propertyName, out incTree)) { incTree = new IncludeTree { PropertyName = propertyName, ResponseProperty = resposeType.GetProperty(propertyName), ModelProperty = Expression.Property(parameter, modelType.GetProperty(propertyName)) }; dic.Add(propertyName, incTree); } } else { IncludeTree child; if (!incTree.Includes.TryGetValue(propertyName, out child)) { child = new IncludeTree { PropertyName = propertyName, ResponseProperty = incTree.ResponseProperty.PropertyType.GetProperty(propertyName), ModelProperty = Expression.Property(incTree.ModelProperty, ((PropertyInfo)incTree.ModelProperty.Member).PropertyType.GetProperty(propertyName)) }; incTree.Includes.Add(propertyName, child); } incTree = child; } } } return(dic.Values.ToArray()); }
protected async Task <TDto> GetImplementation(string id, ListParameters listParameters) { var tuple = await GetUnmapped(id, listParameters); var item = tuple.Item1; IncludeTree tree = tuple.Item2; if (item == null) { return(null); } // Map to DTO var dto = MapObjToDto(item, listParameters.Includes, tree); return(dto); }
public virtual SaveResult <CaseSummaryDtoGen> GetCaseSummary() { var result = new SaveResult <CaseSummaryDtoGen>(); try{ IncludeTree includeTree = null; var objResult = Coalesce.Domain.Case.GetCaseSummary(Db); result.Object = Mapper <Coalesce.Domain.CaseSummary, CaseSummaryDtoGen> .ObjToDtoMapper(objResult, User, "", includeTree); result.WasSuccessful = true; result.Message = null; }catch (Exception ex) { result.WasSuccessful = false; result.Message = ex.Message; } return(result); }
public void IncludeTree_BasicLambdaChecks() { IQueryable <Person> queryable = db.People .Where(e => e.FirstName != null) .Include(p => p.Company) .Include(p => p.CasesAssigned).ThenInclude(c => c.CaseProducts).ThenInclude(c => c.Case.AssignedTo) .Include(p => p.CasesAssigned).ThenInclude(c => c.CaseProducts).ThenInclude(c => c.Case.ReportedBy) .IncludedSeparately(e => e.CasesReported).ThenIncluded(c => c.ReportedBy.Company) .IncludedSeparately(e => e.CasesReported).ThenIncluded(c => c.ReportedBy.CasesAssigned) .Where(e => e.LastName != null); // Just calling this to make sure the query can execute. // There might not be any items that match our precidate, but so long as we don't get exceptions, we don't care what the result is. Person obj = queryable.FirstOrDefault(); IncludeTree tree = queryable.GetIncludeTree(); AssertBasicChecks(tree); }
public virtual SaveResult <PersonDtoGen> Rename(Int32 id, System.String addition) { var result = new SaveResult <PersonDtoGen>(); try{ IncludeTree includeTree = null; var item = DataSource.Includes().FindItem(id); var objResult = item.Rename(addition); Db.SaveChanges(); result.Object = Mapper <Coalesce.Domain.Person, PersonDtoGen> .ObjToDtoMapper(objResult, User, "", includeTree); result.WasSuccessful = true; result.Message = null; }catch (Exception ex) { result.WasSuccessful = false; result.Message = ex.Message; } return(result); }
public virtual async Task <ItemResult <PersonDtoGen> > ChangeFirstName([FromServices] IDataSourceFactory dataSourceFactory, int id, string firstName) { IncludeTree includeTree = null; var dataSource = dataSourceFactory.GetDataSource <Coalesce.Domain.Person, Coalesce.Domain.Person>("Default"); var(itemResult, _) = await dataSource.GetItemAsync(id, new ListParameters()); if (!itemResult.WasSuccessful) { return(new ItemResult <PersonDtoGen>(itemResult)); } var item = itemResult.Object; var methodResult = item.ChangeFirstName(firstName); await Db.SaveChangesAsync(); var result = new ItemResult <PersonDtoGen>(); var mappingContext = new MappingContext(User, ""); result.Object = Mapper.MapToDto <Coalesce.Domain.Person, PersonDtoGen>(methodResult, mappingContext, includeTree); return(result); }
public Expression <Func <T, TResponse> > Select <TResponse>(string include = null) { List <MemberBinding> bindings = new List <MemberBinding>(); foreach (var p in ResponseType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(x => x.CanWrite)) { NavigationPropertyAttribute navAttr = p.GetCustomAttribute <NavigationPropertyAttribute>(); if (navAttr != null) { bindings.Add(Expression.Bind(p, Expression.Property(Expression.Property(Parameter, navAttr.NavigationProperty), navAttr.Property))); } else if (IncludeTree.IsMappeable(p)) { bindings.Add(Expression.Bind(p, Expression.Property(Parameter, p.Name))); } } if (!string.IsNullOrWhiteSpace(include)) { var incTrees = IncludeTree.Build(include, ResponseType, ModelType, Parameter); foreach (var item in incTrees) { bindings.Add(Expression.Bind(item.ResponseProperty, item.CreateInitExpression())); } } MemberInitExpression initExpression = Expression.MemberInit(Expression.New(typeof(TResponse)), bindings); Expression current = Parameter; while (current != null && !(current is ParameterExpression)) { current = ((MemberExpression)current).Expression; } return(Expression.Lambda <Func <T, TResponse> >(initExpression, (ParameterExpression)current)); }
/// <summary> /// Map from the domain object to the properties of the current DTO instance. /// </summary> public override void MapFrom(Coalesce.Starter.Vue.Data.Models.ApplicationUser obj, IMappingContext context, IncludeTree tree = null) { if (obj == null) { return; } var includes = context.Includes; // Fill the properties of the object. this.ApplicationUserId = obj.ApplicationUserId; this.Name = obj.Name; }
// Instance constructor because there is no way to implement a static interface in C#. And generic constructors don't take arguments. public ProductDtoGen CreateInstance(Coalesce.Domain.Product obj, ClaimsPrincipal user = null, string includes = null, Dictionary <object, object> objects = null, IncludeTree tree = null) { return(Create(obj, user, includes, objects, tree)); }
// Create a new version of this object or use it from the lookup. public static ProductDtoGen Create(Coalesce.Domain.Product 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 Product // Applicable excludes for Product // Applicable roles for Product 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((ProductDtoGen)objects[obj]); } var newObject = new ProductDtoGen(); if (tree == null) { objects.Add(obj, newObject); } // Fill the properties of the object. newObject.ProductId = obj.ProductId; newObject.Name = obj.Name; return(newObject); }
// Create a new version of this object or use it from the lookup. public static CaseDtoGen Create(Coalesce.Domain.Case 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 Case // Applicable excludes for Case bool excludePersonListGen = includes == "PersonListGen"; // Applicable roles for Case 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((CaseDtoGen)objects[obj]); } var newObject = new CaseDtoGen(); if (tree == null) { objects.Add(obj, newObject); } // Fill the properties of the object. newObject.CaseKey = obj.CaseKey; newObject.Title = obj.Title; newObject.Description = obj.Description; newObject.OpenedAt = obj.OpenedAt; newObject.AssignedToId = obj.AssignedToId; newObject.ReportedById = obj.ReportedById; newObject.Attachment = obj.Attachment; newObject.Severity = obj.Severity; newObject.Status = obj.Status; newObject.DevTeamAssignedId = obj.DevTeamAssignedId; if (!(excludePersonListGen)) { if (tree == null || tree[nameof(newObject.AssignedTo)] != null) { newObject.AssignedTo = PersonDtoGen.Create(obj.AssignedTo, user, includes, objects, tree?[nameof(newObject.AssignedTo)]); } } if (!(excludePersonListGen)) { if (tree == null || tree[nameof(newObject.ReportedBy)] != null) { newObject.ReportedBy = PersonDtoGen.Create(obj.ReportedBy, user, includes, objects, tree?[nameof(newObject.ReportedBy)]); } } var propValCaseProducts = obj.CaseProducts; if (propValCaseProducts != null && (tree == null || tree[nameof(newObject.CaseProducts)] != null)) { newObject.CaseProducts = propValCaseProducts.OrderBy("CaseProductId ASC").Select(f => CaseProductDtoGen.Create(f, user, includes, objects, tree?[nameof(newObject.CaseProducts)])).ToList(); } else if (propValCaseProducts == null && tree?[nameof(newObject.CaseProducts)] != null) { newObject.CaseProducts = new CaseProductDtoGen[0]; } newObject.DevTeamAssigned = DevTeamDtoGen.Create(obj.DevTeamAssigned, user, includes, objects, tree?[nameof(newObject.DevTeamAssigned)]); return(newObject); }
/// <summary> /// Map from the domain object to the properties of the current DTO instance. /// </summary> public override void MapFrom(Coalesce.Domain.Services.Location obj, IMappingContext context, IncludeTree tree = null) { if (obj == null) { return; } var includes = context.Includes; // Fill the properties of the object. this.City = obj.City; this.State = obj.State; this.Zip = obj.Zip; }
/// <summary> /// Map from the domain object to the properties of the current DTO instance. /// </summary> public override void MapFrom(Coalesce.Domain.External.DevTeam obj, IMappingContext context, IncludeTree tree = null) { if (obj == null) { return; } var includes = context.Includes; // Fill the properties of the object. this.DevTeamId = obj.DevTeamId; this.Name = obj.Name; }
/// <summary> /// Map from the domain object to the properties of the current DTO instance. /// </summary> public override void MapFrom(MMDash.Data.Models.IpLog obj, IMappingContext context, IncludeTree tree = null) { if (obj == null) { return; } var includes = context.Includes; // Fill the properties of the object. this.IpLogId = obj.IpLogId; this.RadioIdLogId = obj.RadioIdLogId; this.LogDateTime = obj.LogDateTime; this.IpAddress = obj.IpAddress; this.Lat = obj.Lat; this.Long = obj.Long; this.CallSignString = obj.CallSignString; if (tree == null || tree[nameof(this.RadioIdLog)] != null) { this.RadioIdLog = obj.RadioIdLog.MapToDto <MMDash.Data.Models.RadioIdLog, RadioIdLogDtoGen>(context, tree?[nameof(this.RadioIdLog)]); } }
/// <summary> /// Map from the domain object to the properties of the current DTO instance. /// </summary> public override void MapFrom(Coalesce.Domain.PersonStats obj, IMappingContext context, IncludeTree tree = null) { if (obj == null) { return; } var includes = context.Includes; // Fill the properties of the object. this.Height = obj.Height; this.Weight = obj.Weight; this.Name = obj.Name; }
/// <summary> /// Map from the domain object to the properties of the current DTO instance. /// </summary> public override void MapFrom(Coalesce.Domain.CaseSummary obj, IMappingContext context, IncludeTree tree = null) { if (obj == null) { return; } var includes = context.Includes; // Fill the properties of the object. this.CaseSummaryId = obj.CaseSummaryId; this.OpenCases = obj.OpenCases; this.CaseCount = obj.CaseCount; this.CloseCases = obj.CloseCases; this.Description = obj.Description; }
/// <summary> /// Map from the domain object to the properties of the current DTO instance. /// </summary> public override void MapFrom(Coalesce.Domain.Person obj, IMappingContext context, IncludeTree tree = null) { if (obj == null) { return; } var includes = context.Includes; // Fill the properties of the object. this.PersonId = obj.PersonId; this.Title = obj.Title; this.FirstName = obj.FirstName; this.LastName = obj.LastName; this.Email = obj.Email; this.Gender = obj.Gender; this.BirthDate = obj.BirthDate; this.LastBath = obj.LastBath; this.NextUpgrade = obj.NextUpgrade; this.Name = obj.Name; this.CompanyId = obj.CompanyId; var propValCasesAssigned = obj.CasesAssigned; if (propValCasesAssigned != null && (tree == null || tree[nameof(this.CasesAssigned)] != null)) { this.CasesAssigned = propValCasesAssigned .AsQueryable().OrderBy("CaseKey ASC").AsEnumerable <Coalesce.Domain.Case>() .Select(f => f.MapToDto <Coalesce.Domain.Case, CaseDtoGen>(context, tree?[nameof(this.CasesAssigned)])).ToList(); } else if (propValCasesAssigned == null && tree?[nameof(this.CasesAssigned)] != null) { this.CasesAssigned = new CaseDtoGen[0]; } var propValCasesReported = obj.CasesReported; if (propValCasesReported != null && (tree == null || tree[nameof(this.CasesReported)] != null)) { this.CasesReported = propValCasesReported .AsQueryable().OrderBy("CaseKey ASC").AsEnumerable <Coalesce.Domain.Case>() .Select(f => f.MapToDto <Coalesce.Domain.Case, CaseDtoGen>(context, tree?[nameof(this.CasesReported)])).ToList(); } else if (propValCasesReported == null && tree?[nameof(this.CasesReported)] != null) { this.CasesReported = new CaseDtoGen[0]; } this.PersonStats = obj.PersonStats.MapToDto <Coalesce.Domain.PersonStats, PersonStatsDtoGen>(context, tree?[nameof(this.PersonStats)]); if (tree == null || tree[nameof(this.Company)] != null) { this.Company = obj.Company.MapToDto <Coalesce.Domain.Company, CompanyDtoGen>(context, tree?[nameof(this.Company)]); } }
/// <summary> /// Map from the domain object to the properties of the current DTO instance. /// </summary> public override void MapFrom(Coalesce.Domain.Company obj, IMappingContext context, IncludeTree tree = null) { if (obj == null) { return; } var includes = context.Includes; // Fill the properties of the object. this.CompanyId = obj.CompanyId; this.Name = obj.Name; this.Address1 = obj.Address1; this.Address2 = obj.Address2; this.City = obj.City; this.State = obj.State; this.ZipCode = obj.ZipCode; this.IsDeleted = obj.IsDeleted; this.AltName = obj.AltName; var propValEmployees = obj.Employees; if (propValEmployees != null && (tree == null || tree[nameof(this.Employees)] != null)) { this.Employees = propValEmployees .AsQueryable().OrderBy("PersonId ASC").AsEnumerable <Coalesce.Domain.Person>() .Select(f => f.MapToDto <Coalesce.Domain.Person, PersonDtoGen>(context, tree?[nameof(this.Employees)])).ToList(); } else if (propValEmployees == null && tree?[nameof(this.Employees)] != null) { this.Employees = new PersonDtoGen[0]; } }