Ejemplo n.º 1
0
 /// <summary>
 /// Pure form for adding a new subject.
 /// </summary>
 /// <param name="yearid">Id of a Year for which we get Subjects.</param>
 public SubjectForm(int yearid) {
     InitializeComponent();
     subjects = new HttpSubjectsRepository();
     subjectLocal = new SubjectsViewModel();
     subjectLocal.year_id = yearid;
     btnSubjectDelete.Enabled = false;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Loads data from given subject to a form.
 /// </summary>
 /// <param name="subject">Subject to be displayed</param>
 private async void LoadData(SubjectsViewModel subject)
 {
     subjects = new HttpSubjectsRepository();
     if ((subjectLocal = await subjects.GetOne(subject.id)) != null)
     {
         txtSubjectDesc.Text = subjectLocal.sub_desc;
         txtSubjectEmail.Text = subjectLocal.teacher_mail;
         txtSubjectName.Text = subjectLocal.name;
         edit = true;
     }
 }
Ejemplo n.º 3
0
        public async Task<IHttpActionResult> PutSubjects(int id, SubjectsViewModel subjects)
        {
            Subjects updatedSubject = await db.Subjects.FindAsync(id); 
            updatedSubject.name = subjects.name;
            updatedSubject.sub_desc = subjects.sub_desc;
            updatedSubject.teacher_mail = subjects.teacher_mail;
            updatedSubject.year_id = subjects.year_id;
            updatedSubject.final_grade = subjects.final_grade;

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor taking existing Subject and filling in the form.
 /// </summary>
 /// <param name="subject">Subject to edit.</param>
 public SubjectForm(SubjectsViewModel subject)
 {
     InitializeComponent();
     LoadData(subject);
     btnSubjectDelete.Enabled = true;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Calls edit form for grade
        /// </summary>
        /// <param name="sub">Subject to which grade will be added</param>
        private void AddGradeToSubject(SubjectsViewModel sub)
        {
            SubjectDetailsViewModel grade = new SubjectDetailsViewModel()
            {
                sub_id = sub.id,
                grade_weight = 1
            };

            var editForm = new EditGradeForm(grade, true);
            editForm.ShowDialog();
            UpdateMainForm();
        }
Ejemplo n.º 6
0
        /*
         * ===============================================
         * Grades Author: Adam
         * ===============================================
         */


        /// <summary>
        /// Creates link labels with grade values.
        /// </summary>
        /// <param name="sub">Subject with grades to show</param>
        private async void CreateGradesLabels(SubjectsViewModel sub)
        {
            var panel = new FlowLayoutPanel(); //panel with grades
            panel.Name = "panel" + sub.id; //set name of the panel to: "panel+subId"
            panel.AutoSize = true;
            tableMarks.Controls.Add(panel); //add panel to tableMarks in proper position
 
            if (sub.SubjectDetails == null)
            {
                return;
            }

            foreach (var grade in sub.SubjectDetails) //populate with labels panel
            {
                if (grade.user_id == currentUser.id)
                {
                    var lbl = new LinkLabel();
                    lbl.Name = grade.id.ToString();
                    lbl.Text = grade.grade_value.ToString();
                    lbl.LinkClicked += ShowGradePanel; //event handler of click
                    lbl.Tag = new Point(grade.id, sub.id); //just 2d vector with id of grade and subject //tmp solution
                    lbl.AutoSize = true;
                    if (visiting)
                    {
                        lbl.Enabled = false;
                    }
                    panel.Controls.Add(lbl);
                }
            }
        }
Ejemplo n.º 7
0
        public async Task<IHttpActionResult> PostSubjects(SubjectsViewModel subjects)
        {
            Subjects newSubject = new Subjects()
            {
                name = subjects.name,
                sub_desc = subjects.sub_desc,
                teacher_mail = subjects.teacher_mail,
                year_id = subjects.year_id,
                final_grade = subjects.final_grade,

            };

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Subjects.Add(newSubject);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = subjects.id }, newSubject);
        }