本文整理汇总了C#中Entity.MapTo方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.MapTo方法的具体用法?C# Entity.MapTo怎么用?C# Entity.MapTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity.MapTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRecordView
private RecordViewResponse CreateRecordView(Entity entity, InputRecordView inputRecordView)
{
RecordViewResponse response = new RecordViewResponse
{
Success = true,
Message = "The record view was successfully created!",
};
if (!inputRecordView.Id.HasValue)
inputRecordView.Id = Guid.NewGuid();
RecordView recordView = inputRecordView.MapTo<RecordView>();
try
{
response.Object = recordView;
response.Errors = ValidateRecordView(entity, inputRecordView, false);
recordView = inputRecordView.MapTo<RecordView>();
if (response.Errors.Count > 0)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The record view was not created. Validation error occurred!";
return response;
}
entity.RecordViews.Add(recordView);
IStorageEntity updatedEntity = entity.MapTo<IStorageEntity>();
bool result = EntityRepository.Update(updatedEntity);
if (!result)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The record view was not created! An internal error occurred!";
return response;
}
}
catch (Exception e)
{
response.Success = false;
response.Object = recordView;
response.Timestamp = DateTime.UtcNow;
#if DEBUG
response.Message = e.Message + e.StackTrace;
#else
response.Message = "The record view was not created. An internal error occurred!";
#endif
return response;
}
return ReadRecordView(entity.Id, recordView.Id);
}
示例2: UpdateRecordView
public RecordViewResponse UpdateRecordView(Entity entity, InputRecordView inputRecordView)
{
RecordViewResponse response = new RecordViewResponse
{
Success = true,
Message = "The record view was successfully updated!",
};
RecordView recordView = inputRecordView.MapTo<RecordView>();
try
{
response.Object = recordView;
response.Errors = ValidateRecordView(entity, inputRecordView, true);
recordView = inputRecordView.MapTo<RecordView>();
if (response.Errors.Count > 0)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The record view was not updated. Validation error occurred!";
return response;
}
RecordView recordViewForDelete = entity.RecordViews.FirstOrDefault(r => r.Id == recordView.Id);
if (recordViewForDelete.Id == recordView.Id)
entity.RecordViews.Remove(recordViewForDelete);
entity.RecordViews.Add(recordView);
IStorageEntity updatedEntity = entity.MapTo<IStorageEntity>();
bool result = EntityRepository.Update(updatedEntity);
if (!result)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The record view was not updated! An internal error occurred!";
return response;
}
}
catch (Exception e)
{
response.Success = false;
response.Object = recordView;
response.Timestamp = DateTime.UtcNow;
#if DEBUG
response.Message = e.Message + e.StackTrace;
#else
response.Message = "The record view was not updated. An internal error occurred!";
#endif
return response;
}
return ReadRecordView(entity.Id, recordView.Id);
}
示例3: CreateRecordTree
private RecordTreeResponse CreateRecordTree(Entity entity, InputRecordTree inputRecordTree)
{
RecordTreeResponse response = new RecordTreeResponse
{
Success = true,
Message = "The tree was successfully created!",
};
if (!inputRecordTree.Id.HasValue)
inputRecordTree.Id = Guid.NewGuid();
RecordTree recordTree = inputRecordTree.MapTo<RecordTree>();
try
{
response.Object = recordTree;
response.Errors = ValidateRecordTree(entity, inputRecordTree);
recordTree = inputRecordTree.MapTo<RecordTree>();
if (response.Errors.Count > 0)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The tree was not created. Validation error occurred!";
return response;
}
entity.RecordTrees.Add(recordTree);
DbEntity updatedEntity = entity.MapTo<DbEntity>();
bool result = DbContext.Current.EntityRepository.Update(updatedEntity);
if (!result)
{
Cache.ClearEntities();
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The tree was not created! An internal error occurred!";
return response;
}
}
catch (Exception e)
{
Cache.ClearEntities();
response.Success = false;
response.Object = recordTree;
response.Timestamp = DateTime.UtcNow;
#if DEBUG
response.Message = e.Message + e.StackTrace;
#else
response.Message = "The tree was not created. An internal error occurred!";
#endif
return response;
}
Cache.ClearEntities();
return ReadRecordTree(entity.Id, recordTree.Id);
}
示例4: UpdateField
public FieldResponse UpdateField(Entity entity, InputField inputField)
{
FieldResponse response = new FieldResponse
{
Success = true,
Message = "The field was successfully updated!",
};
Field field = null;
try
{
response.Errors = ValidateField(entity, inputField, true);
field = inputField.MapTo<Field>();
if (response.Errors.Count > 0)
{
response.Object = field;
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The field was not updated. Validation error occurred!";
return response;
}
Field fieldForDelete = entity.Fields.FirstOrDefault(f => f.Id == field.Id);
if (fieldForDelete.Id == field.Id)
entity.Fields.Remove(fieldForDelete);
entity.Fields.Add(field);
IStorageEntity updatedEntity = entity.MapTo<IStorageEntity>();
bool result = EntityRepository.Update(updatedEntity);
if (!result)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The field was not updated! An internal error occurred!";
return response;
}
}
catch (Exception e)
{
response.Success = false;
response.Object = field;
response.Timestamp = DateTime.UtcNow;
#if DEBUG
response.Message = e.Message + e.StackTrace;
#else
response.Message = "The field was not updated. An internal error occurred!";
#endif
return response;
}
response.Object = field;
response.Timestamp = DateTime.UtcNow;
return response;
}
示例5: UpdateRecordList
public RecordListResponse UpdateRecordList(Entity entity, InputRecordList inputRecordList)
{
RecordListResponse response = new RecordListResponse
{
Success = true,
Message = "The list was successfully updated!",
};
RecordList recordList = inputRecordList.MapTo<RecordList>();
try
{
response.Object = recordList;
response.Errors = ValidateRecordList(entity, inputRecordList, false);
recordList = inputRecordList.MapTo<RecordList>();
if (response.Errors.Count > 0)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The list was not updated. Validation error occurred!";
return response;
}
RecordList listForDelete = entity.RecordLists.FirstOrDefault(r => r.Id == recordList.Id);
if (listForDelete.Id == recordList.Id)
entity.RecordLists.Remove(listForDelete);
entity.RecordLists.Add(recordList);
DbEntity updatedEntity = entity.MapTo<DbEntity>();
bool result = DbContext.Current.EntityRepository.Update(updatedEntity);
if (!result)
{
Cache.ClearEntities();
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The list was not updated! An internal error occurred!";
return response;
}
}
catch (Exception e)
{
Cache.ClearEntities();
response.Success = false;
response.Object = recordList;
response.Timestamp = DateTime.UtcNow;
#if DEBUG
response.Message = e.Message + e.StackTrace;
#else
response.Message = "The list was not updated. An internal error occurred!";
#endif
return response;
}
Cache.ClearEntities();
return ReadRecordList(entity.Id, recordList.Id);
}