コード例 #1
0
        public HttpResponseMessage Get(string securityToken, int Id)
        {
            SchoolResponse response = null;

            if (IsValid(securityToken))
            {
                ISchool schools = new StudentTracking.Application.Main.SchoolService(this._dbContext);
                response = new SchoolResponse {
                    Status = "OK"
                };
                try
                {
                    response.School = schools.Get(Id);
                    if (null == response.School)
                    {
                        response.ErrorCode    = "ERR1002";
                        response.ErrorMessage = string.Format("Invalid School Id: {0}", Id);
                        response.Status       = "Error";
                        CurrentLoggerProvider.Error(string.Format("Invalid Request. School Id: {0}", Id));
                    }
                    else
                    {
                        CurrentLoggerProvider.Info(string.Format("Retrieved School. Id = {0}, Name={1}", response.School.Id, response.School.Name));
                    }
                }
                catch (Exception e)
                {
                    CurrentLoggerProvider.Error(string.Format("Error whiling retrieving School. Id = {0}", Id), e);
                    response.ErrorCode    = "ERR1003";
                    response.ErrorMessage = string.Format("Unable to process request due to technical issue(s). School Id: {0}", Id);
                    response.Status       = "Error";
                }
            }
            else
            {
                response = new SchoolResponse {
                    Status = "Error", ErrorCode = "ERR1001", ErrorMessage = "Invalid or expired token"
                };
                CurrentLoggerProvider.Info(string.Format("Invalid Request. School Id: {0}", Id));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
コード例 #2
0
        public HttpResponseMessage Get(string securityToken, int Id)
        {
            OrganizationResponse response = null;

            if (IsValid(securityToken))
            {
                IOrganization org = new OrganizationService(this._dbContext);

                response = new OrganizationResponse {
                    Status = "OK"
                };
                try
                {
                    response.Organization = org.Get(Id);
                    if (null == response.Organization)
                    {
                        response.ErrorCode    = "ERR1002";
                        response.ErrorMessage = string.Format("Invalid Organization Id: {0}", Id);
                        response.Status       = "Error";
                        CurrentLoggerProvider.Error(string.Format("Invalid Request. Organization Id: {0}", Id));
                    }
                    else
                    {
                        CurrentLoggerProvider.Info(string.Format("Retrieved Organization. Id = {0}, Name={1}", response.Organization.ID, response.Organization.Name));
                    }
                }
                catch (Exception e)
                {
                    CurrentLoggerProvider.Error(string.Format("Error whiling retrieving Organization. Id = {0}", Id), e);
                    response.ErrorCode    = "ERR1003";
                    response.ErrorMessage = string.Format("Unable to process request due to technical issue(s). Organization Id: {0}", Id);
                    response.Status       = "Error";
                }
            }
            else
            {
                response = new OrganizationResponse {
                    Status = "Error", ErrorCode = "ERR1001", ErrorMessage = "Invalid or expired token"
                };
            }
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }