예제 #1
0
 /// <summary>
 /// Default constructor for Year Form
 /// </summary>
 public YearForm()
 {
     InitializeComponent();
     yearsRepo = new HttpYearsRepository();
     txtYearStart.Text = DateTime.Now.ToString("d");
     txtYearEnd.Text = DateTime.Now.AddDays(100).ToString("d");
     yearLocal = new YearsViewModel();
     //yearLocal.user_id = Globals.CurrentUser.id;
 }
예제 #2
0
        /// <summary>
        /// Loads data from given year to a form.
        /// <param name="year">Year to be displayed</param>
        /// </summary>
        private async void LoadData(YearsViewModel year) {

            yearsRepo = new HttpYearsRepository();
            if ((yearLocal = await yearsRepo.GetOne(year.id)) != null)
            {
                txtYearDesc.Text = yearLocal.year_desc;
                txtYearEnd.Text = yearLocal.end_date.ToString("yyyy-MM-dd");
                txtYearStart.Text = yearLocal.start.ToString("yyyy-MM-dd");
                txtYearName.Text = yearLocal.name;
                edit = true;
            }
        }
예제 #3
0
 /// <summary>
 /// Constructor taking existing Year and filling in the form.
 /// </summary>
 /// <param name="year">Year to edit.</param>
 public YearForm(YearsViewModel year)
 {
     InitializeComponent();
     LoadData(year);
 }
예제 #4
0
 /*-----------------------------POPULATING FUNCTIONS-----------------------------*/
 /// <summary>
 /// set Year for which the subjects and grades are supposeed to be displayed
 /// </summary>
 /// <param name="sender">Chosen ComboBox element</param>
 /// <param name="e"></param>
 private async void listYearSelected(object sender, EventArgs e)
 {
     ComboBox cmb = (ComboBox)sender;
     var selectedIndex = (int)cmb.SelectedIndex;
     var item= (YearListItem)cmb.SelectedItem;
     
     if (item.Clickable)
     {
         selectedYear = await years.GetOne(item.Id);
         selectedYearListItem = new YearListItem(item.ToString(), item.Id, item.Clickable, item.Owned);
         UpdateMainForm();
         
     }
     
 }
예제 #5
0
        public async Task<IHttpActionResult> PostYears(YearsViewModel years)
        {
            Years newYear = new Years() { 
                end_date = years.end_date,
                group_id = years.group_id,
                name = years.name,
                start = years.start,
                user_id = years.user_id,
                year_desc = years.year_desc,
            };

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

            db.Years.Add(newYear);
            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var error in e.EntityValidationErrors)
                {
                    foreach (var er in error.ValidationErrors)
                    {
                         string em = er.ErrorMessage;
                    }
                }
                throw;
            }
            

            return CreatedAtRoute("DefaultApi", new { id = years.id }, newYear);
        }
예제 #6
0
        public async Task<IHttpActionResult> PutYears(int id, YearsViewModel years)
        {

            Years updateYear = await db.Years.FindAsync(id);
            updateYear.end_date = years.end_date;
            updateYear.group_id = years.group_id;
            updateYear.name = years.name;
            updateYear.start = years.start;
            updateYear.user_id = years.user_id;
            updateYear.year_desc = years.year_desc;


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

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }