Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }