Ejemplo n.º 1
0
        public HttpResponseMessage UpdateExample(ExampleInfo example)
        {
            try
            {
                var originalExample  = ExampleDataAccess.GetItem(example.ExampleId, example.ModuleId);
                var updatesToProcess = ExampleHasUpdates(ref originalExample, ref example);

                if (updatesToProcess)
                {
                    originalExample.LastUpdatedOnDate   = DateTime.Now;
                    originalExample.LastUpdatedByUserId = UserInfo.UserID;

                    var security = new PortalSecurity();

                    originalExample.Title       = security.InputFilter(originalExample.Title.Trim(), PortalSecurity.FilterFlag.NoMarkup);
                    originalExample.Description = security.InputFilter(originalExample.Description.Trim(), PortalSecurity.FilterFlag.NoMarkup);

                    ExampleDataAccess.UpdateItem(originalExample);
                }

                var savedExample = ExampleDataAccess.GetItem(originalExample.ExampleId, originalExample.ModuleId);

                var response = new ServiceResponse <ExampleInfo> {
                    Content = savedExample
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage CreateExample(ExampleInfo newExample)
        {
            try
            {
                newExample.CreatedOnDate       = DateTime.Now;
                newExample.CreatedByUserId     = UserInfo.UserID;
                newExample.LastUpdatedOnDate   = DateTime.Now;
                newExample.LastUpdatedByUserId = UserInfo.UserID;
                newExample.ModuleId            = ActiveModule.ModuleID;

                var security = new PortalSecurity();

                newExample.Title       = security.InputFilter(newExample.Title.Trim(), PortalSecurity.FilterFlag.NoMarkup);
                newExample.Description = security.InputFilter(newExample.Description.Trim(), PortalSecurity.FilterFlag.NoMarkup);

                ExampleDataAccess.CreateItem(newExample);

                var response = new ServiceResponse <string> {
                    Content = Globals.RESPONSE_SUCCESS
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage DeleteExample(int exampleId)
        {
            try
            {
                ExampleDataAccess.DeleteItem(exampleId, ActiveModule.ModuleID);
                var response = new ServiceResponse <string> {
                    Content = SUCCESS_MESSAGE
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
Ejemplo n.º 4
0
        public HttpResponseMessage GetExample(int exampleId)
        {
            try
            {
                var example  = ExampleDataAccess.GetItem(exampleId, ActiveModule.ModuleID);
                var response = new ServiceResponse <ExampleInfo> {
                    Content = example
                };

                if (example == null)
                {
                    ServiceResponseHelper <ExampleInfo> .AddNoneFoundError("ExampleInfo", ref response);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }