public EntityRelationResponse Update(EntityRelation relation) { EntityRelationResponse response = new EntityRelationResponse(); response.Timestamp = DateTime.UtcNow; response.Object = relation; bool hasPermisstion = SecurityContext.HasMetaPermission(); if (!hasPermisstion) { response.StatusCode = HttpStatusCode.Forbidden; response.Success = false; response.Message = "User have no permissions to manipulate erp meta."; response.Errors.Add(new ErrorModel { Message = "Access denied." }); return(response); } response.Errors = ValidateRelation(relation, ValidationType.Update); if (response.Errors.Count > 0) { response.Success = false; response.Message = "The entity relation was not updated. Validation error occurred!"; return(response); } try { var storageRelation = relation.MapTo <DbEntityRelation>(); var success = DbContext.Current.RelationRepository.Update(storageRelation); Cache.ClearRelations(); if (success) { response.Success = true; response.Message = "The entity relation was successfully updated!"; return(response); } else { response.Success = false; response.Message = "The entity relation was not updated! An internal error occurred!"; return(response); } } catch (Exception e) { Cache.ClearRelations(); response.Success = false; response.Object = relation; response.Timestamp = DateTime.UtcNow; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "The entity relation was not updated. An internal error occurred!"; #endif return(response); } }
public EntityRelationResponse Create(EntityRelation relation) { EntityRelationResponse response = new EntityRelationResponse(); response.Timestamp = DateTime.UtcNow; response.Object = relation; response.Errors = ValidateRelation(relation, ValidationType.Create); if (response.Errors.Count > 0) { response.Success = false; response.Message = "The entity relation was not created. Validation error occurred!"; return(response); } try { var storageRelation = relation.MapTo <DbEntityRelation>(); if (storageRelation.Id == Guid.Empty) { storageRelation.Id = Guid.NewGuid(); } var success = DbContext.Current.RelationRepository.Create(storageRelation); Cache.ClearRelations(); if (success) { response.Success = true; response.Message = "The entity relation was successfully created!"; return(response); } else { response.Success = false; response.Message = "The entity relation was not created! An internal error occurred!"; return(response); } } catch (Exception e) { Cache.ClearRelations(); response.Success = false; response.Object = relation; response.Timestamp = DateTime.UtcNow; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "The entity relation was not created. An internal error occurred!"; #endif return(response); } }
public EntityRelationResponse Update(EntityRelation relation) { EntityRelationResponse response = new EntityRelationResponse(); response.Timestamp = DateTime.UtcNow; response.Object = relation; response.Errors = ValidateRelation(relation, ValidationType.Update); if (response.Errors.Count > 0) { response.Success = false; response.Message = "The entity relation was not updated. Validation error occurred!"; return(response); } try { var storageRelation = relation.MapTo <IStorageEntityRelation>();//ConvertToStorage(relation); var success = relationRepository.Update(storageRelation); if (success) { response.Success = true; response.Message = "The entity relation was successfully updated!"; return(response); } else { response.Success = false; response.Message = "The entity relation was not updated! An internal error occurred!"; return(response); } } catch (Exception e) { response.Success = false; response.Object = relation; response.Timestamp = DateTime.UtcNow; #if DEBUG response.Message = e.Message + e.StackTrace; #else response.Message = "The entity relation was not updated. An internal error occurred!"; #endif return(response); } }
public EntityRelationResponse Create(EntityRelation relation) { EntityRelationResponse response = new EntityRelationResponse(); response.Timestamp = DateTime.UtcNow; response.Object = relation; bool hasPermisstion = SecurityContext.HasMetaPermission(); if (!hasPermisstion) { response.StatusCode = HttpStatusCode.Forbidden; response.Success = false; response.Message = "User have no permissions to manipulate erp meta."; response.Errors.Add(new ErrorModel { Message = "Access denied." }); return(response); } response.Errors = ValidateRelation(relation, ValidationType.Create); if (response.Errors.Count > 0) { response.Success = false; response.Message = "The entity relation was not created. Validation error occurred!"; return(response); } try { var storageRelation = relation.MapTo <DbEntityRelation>(); storageRelation.Name = storageRelation.Name.Trim(); if (storageRelation.Id == Guid.Empty) { storageRelation.Id = Guid.NewGuid(); } var success = DbContext.Current.RelationRepository.Create(storageRelation); Cache.Clear(); if (success) { response.Success = true; response.Message = "The entity relation was successfully created!"; return(response); } else { response.Success = false; response.Message = "The entity relation was not created! An internal error occurred!"; return(response); } } catch (Exception e) { Cache.Clear(); response.Success = false; response.Object = relation; response.Timestamp = DateTime.UtcNow; if (ErpSettings.DevelopmentMode) { response.Message = e.Message + e.StackTrace; } else { response.Message = "The entity relation was not created. An internal error occurred!"; } return(response); } }