コード例 #1
0
        private Response UpdateBadge(int id)
        {
            Badge badge = null;

            try
            {
                badge = this.Bind <Badge>();

                BadgeContext ctx = new BadgeContext();
                ctx.update(badge);

                // 201 - created
                Nancy.Response response = new Nancy.Responses.JsonResponse <Badge>(badge, new DefaultJsonSerializer());
                response.StatusCode = HttpStatusCode.OK;
                // uri
                string uri = this.Request.Url.SiteBase + this.Request.Path + "/" + badge.Id.ToString();
                response.Headers["Location"] = uri;

                return(response);
            }
            catch (Exception e)
            {
                String operation = String.Format("BadgesModule.UpdateBadge({0})", (badge == null) ? "No Model Data" : badge.Title);

                var HandleException = (Response)operation;
                HandleException.StatusCode = HttpStatusCode.InternalServerError;
                return(HandleException);
            }
        }
コード例 #2
0
ファイル: BadgeContext.cs プロジェクト: Raidervz/BSM
        public List <Badge> SearchByName(string parameter = "")
        {
            if (parameter == "")
            {
                return(BadgeContext.GetDatabase().Fetch <Badge>("select * from Badges"));
            }

            string sql = String.Format("select * from Badges where title like '%{0}%' or description like '%{0}%'", parameter);

            return(BadgeContext.GetDatabase().Fetch <Badge>(sql));
        }
コード例 #3
0
        private Response AddBadge()
        {
            Badge badge = null;

            try
            {
                // bind the request body to the object via a Nancy module.
                badge = this.Bind <Badge>();

                // check exists. Return 409 if it does
                if (badge.Id > 0)
                {
                    string errorMessage = String.Format("Use PUT to update an existing Badge with Id = {0}", badge.Id);

                    var ErrorResponse = (Response)errorMessage;
                    ErrorResponse.StatusCode = HttpStatusCode.Conflict;

                    return(ErrorResponse);
                }

                BadgeContext ctx = new BadgeContext();
                ctx.Add(badge);

                // 201 - created
                Nancy.Response response = new Nancy.Responses.JsonResponse <Badge>(badge, new DefaultJsonSerializer());
                response.StatusCode = HttpStatusCode.Created;
                // uri
                string uri = this.Request.Url.SiteBase + this.Request.Path + "/" + badge.Id.ToString();
                response.Headers["Location"] = uri;

                return(response);
            }
            catch (Exception e)
            {
                String operation = String.Format("BadgesModule.AddBadge({0})", (badge == null) ? "No Model Data" : badge.Title);

                var HandleException = (Response)operation;
                HandleException.StatusCode = HttpStatusCode.InternalServerError;
                return(HandleException);
            }
        }
コード例 #4
0
        private Response Search(string param)
        {
            try
            {
                BadgeContext ctx   = new BadgeContext();
                List <Badge> badge = ctx.SearchByName(param);

                Nancy.Response response = new Nancy.Responses.JsonResponse <List <Badge> >(badge, new DefaultJsonSerializer());
                response.StatusCode = HttpStatusCode.OK;
                // uri
                string uri = this.Request.Url.SiteBase + this.Request.Path + "/";
                response.Headers["Location"] = uri;

                return(response);
            }
            catch (Exception e)
            {
                String operation = String.Format("BadgesModule.SearchByName({0})", (param == "") ? "No Model Data" : param.ToString());

                var HandleException = (Response)operation;
                HandleException.StatusCode = HttpStatusCode.InternalServerError;
                return(HandleException);
            }
        }
コード例 #5
0
        private Response GetAll()
        {
            try
            {
                BadgeContext ctx    = new BadgeContext();
                List <Badge> badges = ctx.GetAll();

                Nancy.Response response = new Nancy.Responses.JsonResponse <List <Badge> >(badges, new DefaultJsonSerializer());
                response.StatusCode = HttpStatusCode.OK;
                // uri
                string uri = this.Request.Url.SiteBase + this.Request.Path + "/";
                response.Headers["Location"] = uri;

                return(response);
            }
            catch (Exception e)
            {
                String operation = String.Format("BadgesModule.GetAll()");

                var HandleException = (Response)operation;
                HandleException.StatusCode = HttpStatusCode.InternalServerError;
                return(HandleException);
            }
        }
コード例 #6
0
        private Response GetById(int id)
        {
            try
            {
                BadgeContext ctx   = new BadgeContext();
                Badge        badge = ctx.GetById(id);

                Nancy.Response response = new Nancy.Responses.JsonResponse <Badge>(badge, new DefaultJsonSerializer());
                response.StatusCode = HttpStatusCode.OK;
                // uri
                string uri = this.Request.Url.SiteBase + this.Request.Path + "/" + badge.Id.ToString();
                response.Headers["Location"] = uri;

                return(response);
            }
            catch (Exception e)
            {
                String operation = String.Format("BadgesModule.GetById({0})", (id == 0) ? "No Model Data" : id.ToString());

                var HandleException = (Response)operation;
                HandleException.StatusCode = HttpStatusCode.InternalServerError;
                return(HandleException);
            }
        }
コード例 #7
0
ファイル: BadgeContext.cs プロジェクト: Raidervz/BSM
 public List <Badge> GetAll()
 {
     return(BadgeContext.GetDatabase().Fetch <Badge>("select * from Badges"));
 }
コード例 #8
0
ファイル: BadgeContext.cs プロジェクト: Raidervz/BSM
 internal void delete(Badge badge)
 {
     BadgeContext.GetDatabase().Delete(badge);
 }
コード例 #9
0
ファイル: BadgeContext.cs プロジェクト: Raidervz/BSM
 internal void update(Badge badge)
 {
     BadgeContext.GetDatabase().Update(badge);
 }
コード例 #10
0
ファイル: BadgeContext.cs プロジェクト: Raidervz/BSM
 public void Add(Badge badge)
 {
     BadgeContext.GetDatabase().Insert(badge);
 }
コード例 #11
0
ファイル: BadgeContext.cs プロジェクト: Raidervz/BSM
        public Badge GetById(int id)
        {
            String sql = "select * from Badges where Id =" + id.ToString();

            return(BadgeContext.GetDatabase().FirstOrDefault <Badge>(sql));
        }