// POST api/subjects
        // Notice that we're using the SubjectAdd type in this method
        // We need a Program Id
        public HttpResponseMessage Post(SubjectAdd newSubject)
        {
            if (ModelState.IsValid)
            {
                // Add the new program
                var s = r.AddNew(newSubject);

                // Make sure that we can continue
                if (s == null)
                {
                    // We probably need a better status code...
                    return(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
                }
                else
                {
                    // Build the response object
                    var response = Request.CreateResponse <SubjectFull>(HttpStatusCode.Created, s);

                    // Set the Location header
                    // The "new Uri" object constructor needs a string argument
                    // The ApiController.Url property provides that
                    // Its Link() method takes two arguments...
                    // A route name, which can be seen in App_Start/WebApiConfig.cs, and
                    // A route value, which substitutes for the {id} placeholder
                    response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = s.Id }));

                    return(response);
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
            }
        }
예제 #2
0
        private void btnAddNewItem_Click(object sender, EventArgs e)
        {
            if (rbInstructor.Checked == true)
            {
                var instructorAddForm = new InstructorAdd();
                instructorAddForm.ShowDialog();
            }
            else if (rbSubject.Checked == true)
            {
                var subjectAddForm = new SubjectAdd();
                subjectAddForm.ShowDialog();
            }
            else if (rbNewGroup.Checked == true)
            {
                var groupAddForm = new GroupAdd();
                groupAddForm.ShowDialog();
            }
            else if (rbNewMeeting.Checked == true)
            {
                var meetingAddForm = new MeetingAdd();
                meetingAddForm.ShowDialog();
            }

            else if (rbSubToSubType.Checked == true)
            {
                var subToSubTypeAddForm = new SubToSubTypeAdd();
                subToSubTypeAddForm.ShowDialog();
            }

            else if (rbInsToSub.Checked == true)
            {
                var insSubAddForm = new InsSubAdd();
                insSubAddForm.ShowDialog();
            }
        }
예제 #3
0
        // Add new item
        public Subject AddSubject(SubjectAdd Subject)
        {
            // Map from DTO object to domain (POCO) object
            var p = ds.Subjects.Add(Mapper.Map <ICTGWS.Models.Subject>(Subject));

            ds.SaveChanges();
            // Map to DTO object
            return(Mapper.Map <Subject>(p));
        }
예제 #4
0
        public IActionResult Add(SubjectAdd subjectAdd)
        {
            if (!ModelState.IsValid)
            {
                return(View("Add", subjectAdd));
            }

            using (var db = new SchoolContext())
            {
                var subject = new Subject
                {
                    SubjectName = subjectAdd.Name,
                    TeacherId   = subjectAdd.TeacherId
                };

                db.Subjects.Add(subject);
                db.SaveChanges();
            }

            return(RedirectToActionPermanent("Index", "Subject"));
        }