예제 #1
0
 public static void DisposeEntityContext(LinqEntityContextWindows context)
 {
     if (context != null)
     {
         context.Dispose();
     }
 }
 public RestServicePutEntityEventArgsWindows(
     string entityName,
     Nullable <Guid> userId,
     string userName,
     LinqEntityContextWindows entityContext,
     Type entityType,
     object inputEntity)
     : base(entityName, userId, userName, entityContext, entityType)
 {
     _inputEntity = inputEntity;
 }
예제 #3
0
 public RestServiceDeleteEntityEventArgsWindows(
     string entityName,
     Nullable <Guid> userId,
     string userName,
     LinqEntityContextWindows entityContext,
     Type entityType,
     string entityId)
     : base(entityName, userId, userName, entityContext, entityType)
 {
     _entityId = entityId;
 }
예제 #4
0
 public RestServiceGetEntitiesEventArgsWindows(
     string entityName,
     Nullable <Guid> userId,
     string userName,
     LinqEntityContextWindows entityContext,
     Type entityType,
     List <object> outputEntities)
     : base(entityName, userId, userName, entityContext, entityType)
 {
     _outputEntities = outputEntities;
 }
예제 #5
0
        public virtual Stream PostEntity(string entityName, Stream inputStream)
        {
            LinqEntityContextWindows context = null;

            try
            {
                string requestName = $"{nameof(PostEntity)} : Entity Name = {entityName}";
                ValidateRequestMethod(HttpVerb.POST);
                context = GetEntityContext();
                Nullable <Guid> userId     = null;
                string          userName   = null;
                Type            entityType = GetEntityType(entityName);
                GetUserDetails(context, out userId, out userName);
                object inputEntity = GetObjectFromStream(entityType, inputStream, GOCWindows.Instance.JsonSerializer, out string serializedText);
                AuditRequest(requestName, serializedText);
                if (OnBeforePost != null)
                {
                    OnBeforePost(this, new RestServicePostEntityEventArgsWindows(
                                     entityName, userId, userName, context, entityType, inputEntity));
                }
                context.Insert(
                    entityType,
                    new List <object>()
                {
                    inputEntity
                },
                    userId,
                    userName,
                    false);
                if (OnAfterPost != null)
                {
                    OnAfterPost(this, new RestServicePostEntityEventArgsWindows(
                                    entityName, userId, userName, context, entityType, inputEntity));
                }
                string responseMessage = string.Format("{0} saved successfully.", entityName);
                Stream result          = StreamHelper.GetStreamFromString(responseMessage, GOCWindows.Instance.Encoding);
                AuditResponse(requestName, responseMessage);
                return(result);
            }
            catch (Exception ex)
            {
                if (_handleExceptions)
                {
                    ExceptionHandlerWindows.HandleException(ex, null);
                }
                UpdateHttpStatusOnException(ex);
                throw ex;
            }
            finally
            {
                DisposeEntityContext(context);
            }
        }
 public RestServiceEventArgsWindows(
     string entityName,
     Nullable <Guid> userId,
     string userName,
     LinqEntityContextWindows entityContext,
     Type entityType)
 {
     _entityName    = entityName;
     _userId        = userId;
     _userName      = userName;
     _entityContext = entityContext;
     _entityType    = entityType;
 }
 public RestServiceGetEntityByIdEventArgsWindows(
     string entityName,
     Nullable <Guid> userId,
     string userName,
     LinqEntityContextWindows entityContext,
     Type entityType,
     string entityId,
     object outputEntity)
     : base(entityName, userId, userName, entityContext, entityType)
 {
     _entityId     = entityId;
     _outputEntity = outputEntity;
 }
예제 #8
0
 protected virtual void GetUserDetails(LinqEntityContextWindows context, out Nullable <Guid> userId, out string userName)
 {
     userId   = null;
     userName = null;
     if (ServiceSecurityContext.Current != null && !string.IsNullOrEmpty(ServiceSecurityContext.Current.WindowsIdentity.Name))
     {
         if (context != null && context.UserLinqToSqlType != null)
         {
             userId = context.GetUserId(ServiceSecurityContext.Current.WindowsIdentity.Name);
         }
         userName = ServiceSecurityContext.Current.WindowsIdentity.Name;
     }
 }
예제 #9
0
        public virtual Stream DeleteEntity(string entityName, string entityId)
        {
            LinqEntityContextWindows context = null;

            try
            {
                string requestName = $"{nameof(DeleteEntity)} : Entity Name = {entityName} : Entity ID = {entityId}";
                AuditRequest(requestName, null);
                ValidateRequestMethod(HttpVerb.DELETE);
                context = GetEntityContext();
                Nullable <Guid> userId   = null;
                string          userName = null;
                GetUserDetails(context, out userId, out userName);
                Type entityType = GetEntityType(entityName);
                if (OnBeforeDelete != null)
                {
                    OnBeforeDelete(this, new RestServiceDeleteEntityEventArgsWindows(
                                       entityName, userId, userName, context, entityType, entityId));
                }
                context.DeleteBySurrogateKey(
                    entityType,
                    new List <object>()
                {
                    entityId
                },
                    userId,
                    userName);
                if (OnAfterDelete != null)
                {
                    OnAfterDelete(this, new RestServiceDeleteEntityEventArgsWindows(
                                      entityName, userId, userName, context, entityType, entityId));
                }
                string responseMessage = string.Format("{0} deleted successfully.", entityName);
                Stream result          = StreamHelper.GetStreamFromString(responseMessage, GOCWindows.Instance.Encoding);
                AuditResponse(requestName, responseMessage);
                return(result);
            }
            catch (Exception ex)
            {
                if (_handleExceptions)
                {
                    ExceptionHandlerWindows.HandleException(ex, null);
                }
                UpdateHttpStatusOnException(ex);
                throw ex;
            }
            finally
            {
                DisposeEntityContext(context);
            }
        }
예제 #10
0
        public virtual Stream GetEntitiesByField(string entityName, string fieldName, string fieldValue)
        {
            LinqEntityContextWindows context = null;

            try
            {
                string requestName = $"{nameof(GetEntitiesByField)} : Entity Name = {entityName} : Field Name = {fieldName} : Field Value = {fieldValue}";
                AuditRequest(requestName, null);
                ValidateRequestMethod(HttpVerb.GET);
                context = GetEntityContext();
                Nullable <Guid> userId   = null;
                string          userName = null;
                GetUserDetails(context, out userId, out userName);
                Type entityType = GetEntityType(entityName);
                if (OnBeforeGetEntitiesByField != null)
                {
                    OnBeforeGetEntitiesByField(this, new RestServiceGetEntitiesByFieldEventArgsWindows(
                                                   entityName, userId, userName, context, entityType, fieldName, fieldValue, null));
                }
                List <object> outputEntities = context.GetEntitiesByField(
                    entityType,
                    fieldName,
                    fieldValue,
                    false,
                    userId,
                    userName).Contents;
                if (OnAfterGetEntitiesByField != null)
                {
                    OnAfterGetEntitiesByField(this, new RestServiceGetEntitiesByFieldEventArgsWindows(
                                                  entityName, userId, userName, context, entityType, fieldName, fieldValue, outputEntities));
                }
                Stream result = GetStreamFromObject(outputEntities, out string serializedText);
                AuditResponse(requestName, serializedText);
                return(result);
            }
            catch (Exception ex)
            {
                if (_handleExceptions)
                {
                    ExceptionHandlerWindows.HandleException(ex, null);
                }
                UpdateHttpStatusOnException(ex);
                throw ex;
            }
            finally
            {
                DisposeEntityContext(context);
            }
        }