Exemplo n.º 1
0
        public SchuelerModule(SchuelerService schuelerService)
            : base("/schueler")
        {
            Get["/"] = p =>
            {
                var schueler = schuelerService.Get();
                return(new JsonResponse(schueler, new JsonNetSerializer()));
            };

            Get["/{id}"] = p =>
            {
                var schueler = schuelerService.Get(p.id);
                if (schueler == null)
                {
                    return(HttpStatusCode.NotFound);
                }
                return(new JsonResponse(schueler, new JsonNetSerializer()));
            };


            Post["/"] = p =>
            {
                Schueler post = this.Bind();
                try
                {
                    var result = schuelerService.Add(post);
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
                return(HttpStatusCode.Created);
            };

            Put["/"] = p =>
            {
                Schueler put = this.Bind();
                try
                {
                    var result = schuelerService.Update(put);
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
                return(HttpStatusCode.OK);
            };

            Delete["/{id}"] = p =>
            {
                try
                {
                    var result = schuelerService.Delete(p.id);
                    return(new JsonResponse(result, new DefaultJsonSerializer()));
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
            };
        }
Exemplo n.º 2
0
        public Foerderkurs_Schueler_Module(Foerderkurs_Schueler_Service foerderkurs_schueler_Service, foerderkursService foederkursService, SchuelerService schuelerService)
            : base("/foederkurs_schueler")
        {
            //Passwortabsicherung des Moduls
            //this.RequiresAuthentication();

            Get["/"] = p =>
            {
                var foeSch = foerderkurs_schueler_Service.Get();
                return(new JsonResponse(aufArt, new JsonNetSerializer()));
            };

            Get["/bySchuelerID/{id}"] = p =>
            {
                var foeSch = foerderkurs_schueler_Service.GetBySchueler(p.id);
                return(new JsonResponse(foeSch, new JsonNetSerializer()));
            };


            Post["/"] = p =>
            {
                foerderkurs_Schueler post = this.Bind();
                try
                {
                    var result = foerderkurs_schueler_Service.Add(post);
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    Console.WriteLine(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
                return(HttpStatusCode.Created);
            };

            Post["/Schueler/{schuelerID}/Foerderkurs/{foederkursID}"] = p =>
            {
                Schueler   sch = schuelerService.Get(p.SchuelerID);
                Foederkurs foe = foerderkursService.Get(p.FoederkursID);

                Foerderkurs_Schueler post = this.Bind();
                post.Schueler    = sch;
                post.Foerderkurs = foe;

                sch.foerderkursSchueler.Add(post);
                foe.foerderkursSchueler.Add(post);

                try
                {
                    var result = foerderkurs_schueler_Service.Add(post);
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    Console.WriteLine(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
                return(HttpStatusCode.Created);
            };

            Put["/"] = p =>
            {
                foederkurs_Schueler put = this.Bind();
                try
                {
                    var result = foerderkurs_schueler_Service.Update(put);
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
                return(HttpStatusCode.OK);
            };

            Delete["/{id}"] = p =>
            {
                try
                {
                    var result = foerderkurs_schueler_Service.Delete(p.id);
                    return(new JsonResponse(result, new DefaultJsonSerializer()));
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
            };
        }