Exemplo n.º 1
0
        public IActionResult DeleteEntity(string StringId)
        {
            EntityResponse response = new EntityResponse();

            // Parse each string representation.
            Guid newGuid;
            Guid id = Guid.Empty;
            if (Guid.TryParse(StringId, out newGuid))
            {
                response = entMan.DeleteEntity(newGuid);
            }
            else
            {
                response.Success = false;
                response.Message = "The entity Id should be a valid Guid";
                HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            return DoResponse(response);
        }
Exemplo n.º 2
0
        public EntityResponse CreateEntity(InputEntity inputEntity)
        {
            EntityResponse response = new EntityResponse
            {
                Success = true,
                Message = "The entity was successfully created!",
            };

            //in order to support external IDs (while import in example)
            //we generate new ID only when it is not specified
            if (!inputEntity.Id.HasValue)
                inputEntity.Id = Guid.NewGuid();

            Entity entity = inputEntity.MapTo<Entity>();

            try
            {
                response.Object = entity;

                response.Errors = ValidateEntity(entity, false);

                if (response.Errors.Count > 0)
                {
                    response.Timestamp = DateTime.UtcNow;
                    response.Success = false;
                    response.Message = "The entity was not created. Validation error occurred!";
                    return response;
                }

                entity.Fields = CreateEntityDefaultFields(entity);
                entity.RecordLists = CreateEntityDefaultRecordLists(entity);
                entity.RecordViews = CreateEntityDefaultRecordViews(entity);

                IStorageEntity storageEntity = entity.MapTo<IStorageEntity>();
                bool result = EntityRepository.Create(storageEntity);
                if (!result)
                {
                    response.Timestamp = DateTime.UtcNow;
                    response.Success = false;
                    response.Message = "The entity was not created! An internal error occurred!";
                    return response;
                }

                //TODO: create records collection

            }
            catch (Exception e)
            {
                response.Success = false;
                response.Object = entity;
                response.Timestamp = DateTime.UtcNow;
            #if DEBUG
                response.Message = e.Message + e.StackTrace;
            #else
                response.Message = "The entity was not created. An internal error occurred!";
            #endif
                return response;
            }

            IStorageEntity createdEntity = EntityRepository.Read(entity.Id);
            response.Object = createdEntity.MapTo<Entity>();
            response.Timestamp = DateTime.UtcNow;

            return response;
        }
Exemplo n.º 3
0
        //        public EntityResponse PartialUpdateEntity(Guid id, InputEntity inputEntity)
        //        {
        //            EntityResponse response = new EntityResponse
        //            {
        //                Success = true,
        //                Message = "The entity was successfully updated!",
        //            };
        //            Entity entity = null;
        //            try
        //            {
        //                IStorageEntity storageEntity = EntityRepository.Read(id);
        //                entity = storageEntity.MapTo<Entity>();
        //                if (inputEntity.Label != null)
        //                    entity.Label = inputEntity.Label;
        //                if (inputEntity.LabelPlural != null)
        //                    entity.LabelPlural = inputEntity.LabelPlural;
        //                if (inputEntity.System != null)
        //                    entity.System = inputEntity.System.Value;
        //                if (inputEntity.IconName != null)
        //                    entity.IconName = inputEntity.IconName;
        //                if (inputEntity.Weight != null)
        //                    entity.Weight = inputEntity.Weight.Value;
        //                if (inputEntity.RecordPermissions != null)
        //                    entity.RecordPermissions = inputEntity.RecordPermissions;
        //                response.Object = entity;
        //                response.Errors = ValidateEntity(entity, true);
        //                if (response.Errors.Count > 0)
        //                {
        //                    response.Timestamp = DateTime.UtcNow;
        //                    response.Success = false;
        //                    response.Message = "The entity was not updated. Validation error occurred!";
        //                    return response;
        //                }
        //                storageEntity = entity.MapTo<IStorageEntity>();
        //                bool result = EntityRepository.Update(storageEntity);
        //                if (!result)
        //                {
        //                    response.Timestamp = DateTime.UtcNow;
        //                    response.Success = false;
        //                    response.Message = "The entity was not updated! An internal error occurred!";
        //                    return response;
        //                }
        //            }
        //            catch (Exception e)
        //            {
        //                response.Success = false;
        //                response.Object = entity;
        //                response.Timestamp = DateTime.UtcNow;
        //#if DEBUG
        //                response.Message = e.Message + e.StackTrace;
        //#else
        //                response.Message = "The entity was not updated. An internal error occurred!";
        //#endif
        //                return response;
        //            }
        //            IStorageEntity updatedEntity = EntityRepository.Read(entity.Id);
        //            response.Object = updatedEntity.MapTo<Entity>();
        //            response.Timestamp = DateTime.UtcNow;
        //            return response;
        //        }
        public EntityResponse DeleteEntity(Guid id)
        {
            EntityResponse response = new EntityResponse
            {
                Success = true,
                Message = "The entity was successfully deleted!",
            };

            try
            {
                IStorageEntity entity = EntityRepository.Read(id);

                if (entity == null)
                {
                    response.Timestamp = DateTime.UtcNow;
                    response.Success = false;
                    response.Message = "The entity was not deleted. Validation error occurred!";
                    response.Errors.Add(new ErrorModel("id", id.ToString(), "Entity with such Id does not exist!"));
                    return response;
                }

                //entity, entity records and relations are deleted in storage repository
                EntityRepository.Delete(id);
            }
            catch (Exception e)
            {
                response.Timestamp = DateTime.UtcNow;
                response.Success = false;
            #if DEBUG
                response.Message = e.Message + e.StackTrace;
            #else
                response.Message = "The entity was not deleted. An internal error occurred!";
            #endif
                return response;
            }

            response.Timestamp = DateTime.UtcNow;
            return response;
        }
Exemplo n.º 4
0
        public EntityResponse UpdateEntity(InputEntity inputEntity)
        {
            EntityResponse response = new EntityResponse
            {
                Success = true,
                Message = "The entity was successfully updated!",
            };

            Entity entity = inputEntity.MapTo<Entity>();

            try
            {
                response.Object = entity;
                response.Errors = ValidateEntity(entity, true);

                if (response.Errors.Count > 0)
                {
                    response.Timestamp = DateTime.UtcNow;
                    response.Success = false;
                    response.Message = "The entity was not updated. Validation error occurred!";
                    return response;
                }

                IStorageEntity storageEntity = EntityRepository.Read(entity.Id);

                storageEntity.Label = entity.Label;
                storageEntity.LabelPlural = entity.LabelPlural;
                storageEntity.System = entity.System;
                storageEntity.IconName = entity.IconName;
                storageEntity.Weight = entity.Weight;
                storageEntity.RecordPermissions.CanRead = entity.RecordPermissions.CanRead;
                storageEntity.RecordPermissions.CanCreate = entity.RecordPermissions.CanCreate;
                storageEntity.RecordPermissions.CanUpdate = entity.RecordPermissions.CanUpdate;
                storageEntity.RecordPermissions.CanDelete = entity.RecordPermissions.CanDelete;

                bool result = EntityRepository.Update(storageEntity);

                if (!result)
                {
                    response.Timestamp = DateTime.UtcNow;
                    response.Success = false;
                    response.Message = "The entity was not updated! An internal error occurred!";
                    return response;
                }

            }
            catch (Exception e)
            {
                response.Success = false;
                response.Object = entity;
                response.Timestamp = DateTime.UtcNow;
            #if DEBUG
                response.Message = e.Message + e.StackTrace;
            #else
                response.Message = "The entity was not updated. An internal error occurred!";
            #endif
                return response;
            }

            IStorageEntity updatedEntity = EntityRepository.Read(entity.Id);
            response.Object = updatedEntity.MapTo<Entity>();
            response.Timestamp = DateTime.UtcNow;

            return response;
        }
Exemplo n.º 5
0
        public EntityResponse ReadEntity(string name)
        {
            EntityResponse response = new EntityResponse
            {
                Success = true,
                Message = "The entity was successfully returned!",
                Timestamp = DateTime.UtcNow
            };

            try
            {
                EntityListResponse entityListResponse = ReadEntities();

                if (entityListResponse != null && entityListResponse.Object != null)
                {
                    List<Entity> entities = entityListResponse.Object.Entities;

                    Entity entity = entities.FirstOrDefault(e => e.Name == name);
                    if (entity != null)
                        response.Object = entity;
                }
            }
            catch (Exception e)
            {
                response.Timestamp = DateTime.UtcNow;
                response.Success = false;
            #if DEBUG
                response.Message = e.Message + e.StackTrace;
            #else
                response.Message = "An internal error occurred!";
            #endif
                return response;
            }

            response.Timestamp = DateTime.Now;

            return response;
        }
Exemplo n.º 6
0
        public EntityResponse CreateEntity(InputEntity inputEntity, bool createDefaultViews = true, bool createDefaultLists = true, Dictionary<string,Guid> sysIdDictionary = null)
        {
            EntityResponse response = new EntityResponse
            {
                Success = true,
                Message = "The entity was successfully created!",
            };

            //in order to support external IDs (while import in example)
            //we generate new ID only when it is not specified
            if (!inputEntity.Id.HasValue)
                inputEntity.Id = Guid.NewGuid();

            Entity entity = inputEntity.MapTo<Entity>();

            try
            {
                response.Object = entity;

                response.Errors = ValidateEntity(entity, false);

                if (response.Errors.Count > 0)
                {
                    response.Timestamp = DateTime.UtcNow;
                    response.Success = false;
                    response.Message = "The entity was not created. Validation error occurred!";
                    return response;
                }

                entity.Fields = CreateEntityDefaultFields(entity, sysIdDictionary);
                if (createDefaultViews)
                {
                    entity.RecordViews = CreateEntityDefaultRecordViews(entity);
                }
                else
                {
                    entity.RecordViews = new List<RecordView>();
                }
                if (createDefaultLists)
                {
                    entity.RecordLists = CreateEntityDefaultRecordLists(entity);
                }
                else
                {
                    entity.RecordLists = new List<RecordList>();
                }

                DbEntity storageEntity = entity.MapTo<DbEntity>();
                bool result = DbContext.Current.EntityRepository.Create(storageEntity, sysIdDictionary );
                if (!result)
                {
                    response.Timestamp = DateTime.UtcNow;
                    response.Success = false;
                    response.Message = "The entity was not created! An internal error occurred!";
                    return response;
                }
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Object = entity;
                response.Timestamp = DateTime.UtcNow;
            #if DEBUG
                response.Message = e.Message + e.StackTrace;
            #else
                response.Message = "The entity was not created. An internal error occurred!";
            #endif
                return response;
            }

            Cache.ClearEntities();

            var createdEntityResponse = ReadEntity(entity.Id);
            response.Object = createdEntityResponse.Object;
            response.Timestamp = DateTime.UtcNow;

            return response;
        }