本文整理汇总了C#中InputField.MapTo方法的典型用法代码示例。如果您正苦于以下问题:C# InputField.MapTo方法的具体用法?C# InputField.MapTo怎么用?C# InputField.MapTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputField
的用法示例。
在下文中一共展示了InputField.MapTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateField
public FieldResponse CreateField(Guid entityId, InputField inputField, bool transactional = true)
{
FieldResponse response = new FieldResponse
{
Success = true,
Message = "The field was successfully created!",
};
Field field = null;
try
{
IStorageEntity storageEntity = EntityRepository.Read(entityId);
if (storageEntity == null)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "Entity with such Id does not exist!";
return response;
}
if (inputField.Id == null || inputField.Id == Guid.Empty)
inputField.Id = Guid.NewGuid();
Entity entity = storageEntity.MapTo<Entity>();
response.Errors = ValidateField(entity, inputField, false);
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 created. Validation error occurred!";
return response;
}
entity.Fields.Add(field);
IStorageEntity editedEntity = entity.MapTo<IStorageEntity>();
var recRep = Storage.GetRecordRepository();
var transaction = recRep.CreateTransaction();
try
{
if (transactional)
transaction.Begin();
recRep.CreateRecordField(entity.Name, field.Name, field.GetDefaultValue());
bool result = EntityRepository.Update(editedEntity);
if (!result)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The field was not created! An internal error occurred!";
return response;
}
if (transactional)
transaction.Commit();
}
catch
{
if (transactional)
transaction.Rollback();
throw;
}
}
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 created. An internal error occurred!";
#endif
return response;
}
response.Object = field;
response.Timestamp = DateTime.UtcNow;
return response;
}
示例2: 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;
}
示例3: CreateField
public FieldResponse CreateField(Guid entityId, InputField inputField, bool transactional = true)
{
FieldResponse response = new FieldResponse
{
Success = true,
Message = "The field was successfully created!",
};
Field field = null;
try
{
var entityResponse = ReadEntity(entityId);
if (!entityResponse.Success)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = entityResponse.Message;
return response;
}
else if (entityResponse.Object == null)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "Entity with such Id does not exist!";
return response;
}
Entity entity = entityResponse.Object;
if (inputField.Id == null || inputField.Id == Guid.Empty)
inputField.Id = Guid.NewGuid();
response.Errors = ValidateField(entity, inputField, false);
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 created. Validation error occurred!";
return response;
}
entity.Fields.Add(field);
DbEntity editedEntity = entity.MapTo<DbEntity>();
using (DbConnection con = DbContext.Current.CreateConnection())
{
con.BeginTransaction();
try
{
bool result = DbContext.Current.EntityRepository.Update(editedEntity);
if (!result)
{
response.Timestamp = DateTime.UtcNow;
response.Success = false;
response.Message = "The field was not created! An internal error occurred!";
return response;
}
DbContext.Current.RecordRepository.CreateRecordField(entity.Name, field);
con.CommitTransaction();
}
catch
{
con.RollbackTransaction();
throw;
}
}
}
catch (Exception e)
{
Cache.ClearEntities();
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 created. An internal error occurred!";
#endif
return response;
}
Cache.ClearEntities();
response.Object = field;
response.Timestamp = DateTime.UtcNow;
return response;
}