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


C# Entity.MapTo方法代码示例

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

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

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

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

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


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