当前位置: 首页>>代码示例>>C#>>正文


C# InputField.MapTo方法代码示例

本文整理汇总了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;
        }
开发者ID:njmube,项目名称:WebVella-ERP,代码行数:91,代码来源:EntityManager.cs

示例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;
        }
开发者ID:njmube,项目名称:WebVella-ERP,代码行数:60,代码来源:EntityManager.cs

示例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;
        }
开发者ID:nhannv,项目名称:WebVella-ERP,代码行数:99,代码来源:EntityManager.cs


注:本文中的InputField.MapTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。