public async Task<IHttpActionResult> PostApprovedCourse(ApprovedCourse approvedCourse)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.approvedCourses.Add(approvedCourse);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ApprovedCourseExists(approvedCourse.id))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = approvedCourse.id }, approvedCourse);
        }
        public async Task<IHttpActionResult> PutApprovedCourse(string id, ApprovedCourse approvedCourse)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != approvedCourse.id)
            {
                return BadRequest();
            }

            db.Entry(approvedCourse).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ApprovedCourseExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #3
0
        private void PopulateCourse()
        {
            Course dat304 = new Course()
            {
                id = "DAT-304",
                name = "DAT-304 - Dataing., bachelor"
            };

            Course is304 = new Course()
            {
                id = "IS-304",
                name = "IS-304 - Informasjonssys., bachelor"
            };
            Course be501 = new Course()
            {
                id = "BE-501",
                name = "BE-501 - Øk.adm., master"
            };
            Course bio300 = new Course()
            {
                id = "BIO-300",
                name = "BIO-300 - Biologi, bachelor"
            };
            Course bio500 = new Course()
            {
                id = "BIO-500",
                name = "BIO-500 - Akvatisk økologi, master"
            };
            Course byg300 = new Course()
            {
                id = "BYG-300",
                name = "BYG-300 - Byggdesign, bachelor"
            };
            Course byg500 = new Course()
            {
                id = "BYG-500",
                name = "BYG-500 - Bygg, siv.ing. master"
            };

            Course dat303 = new Course()
            {
                id = "DAT-303",
                name = "DAT-303 - Multimedia, bachelor"
            };
            Course ele301 = new Course()
            {
                id = "ELE-303",
                name = "ELE-303 - Elektronikk, bachelor"
            };
            Course ene304g = new Course()
            {
                id = "ENE-304-G",
                name = "ENE-304-G - Energi hovedprosjekt, bachelor"
            };
            Course ikt590 = new Course()
            {
                id = "IKT-590",
                name = "IKT-590 - IKT, master"
            };
            Course ind590 = new Course()
            {
                id = "IND-590",
                name = "IND-590 - Ind.øk. og tek.led., master"
            };
            Course is302 = new Course()
            {
                id = "IS-302",
                name = "IS-302, Praksisprosjekt i infosys., bachelor"
            };
            Course is501 = new Course()
            {
                id = "IS-501",
                name = "IS-501 - Informasjonssys., master"
            };
            Course kom207 = new Course()
            {
                id = "KOM-207",
                name = "KOM-207 -- Kommunikasjon, bachelor"
            };
            Course kom500 = new Course()
            {
                id = "KOM-500",
                name = "KOM-500 - Samfunnskom., master"
            };
            Course ma302 = new Course()
            {
                id = "MA-302",
                name = "MA-302 - Matematikk, bachelor"
            };
            Course ma500 = new Course()
            {
                id = "MA-500",
                name = "MA-500 - Matematikkdid., master"
            };
            Course mas306 = new Course()
            {
                id = "MAS-306",
                name = "MAS-306 - Mekatronikk, bachelor"
            };
            Course mas500 = new Course()
            {
                id = "MAS-500",
                name = "MAS-500 - Mekatronikk, master"
            };
            Course me502 = new Course()
            {
                id = "ME-502",
                name = "ME-502 - Off.pol og ledelse, master"
            };
            Course me504 = new Course()
            {
                id = "ME-504",
                name = "ME-504 - Psyk. helsearbeid, master"
            };
            Course ml312 = new Course()
            {
                id = "ML-312",
                name = "ML-312 - Bioing., bachelor"
            };
            Course mm500 = new Course()
            {
                id = "MM-500",
                name = "MM-500 - Multimedia, master"
            };
            Course org500 = new Course()
            {
                id = "ORG-500",
                name = "ORG-500 - Ledelse, master"
            };
            Course ped233 = new Course()
            {
                id = "PED-233",
                name = "PED-233 - Lærer (1.-7.trinn), bachelor"
            };
            Course sv301 = new Course()
            {
                id = "SV-301",
                name = "SV-301, Samfunnsplanlegging, bachelor"
            };
            Course sv303 = new Course()
            {
                id = "SV-303",
                name = "SV-303, Sosialt arbeid, bachelor"
            };
            Course ut503 = new Course()
            {
                id = "UT-503",
                name = "UT-503 - Utvikling og samf.plan.,master"
            };
            db.courses.Add(dat304);
            db.courses.Add(be501);
            db.courses.Add(bio300);
            db.courses.Add(bio500);
            db.courses.Add(byg300);
            db.courses.Add(byg500);
            db.courses.Add(dat303);
            db.courses.Add(dat304);
            db.courses.Add(ele301);
            db.courses.Add(ene304g);
            db.courses.Add(ikt590);
            db.courses.Add(ind590);
            db.courses.Add(is302);
            db.courses.Add(is304);
            db.courses.Add(is501);
            db.courses.Add(kom207);
            db.courses.Add(kom500);
            db.courses.Add(ma302);
            db.courses.Add(ma500);
            db.courses.Add(mas306);
            db.courses.Add(mas500);
            db.courses.Add(me502);
            db.courses.Add(me504);
            db.courses.Add(ml312);
            db.courses.Add(mm500);
            db.courses.Add(org500);
            db.courses.Add(ped233);
            db.courses.Add(sv301);
            db.courses.Add(sv303);
            db.courses.Add(ut503);


            db.SaveChanges();

            ApprovedCourse dat3041 = new ApprovedCourse()
            {
                id = "DAT-304",
                name = "DAT-304 - Dataing., bachelor"
            };

            ApprovedCourse is3041 = new ApprovedCourse()
            {
                id = "IS-304",
                name = "IS-304 - Informasjonssys., bachelor"
            };

            db.approvedCourses.Add(dat3041);
            db.approvedCourses.Add(is3041);
            db.SaveChanges();
        }