Ejemplo n.º 1
0
 public T_InstanceOfCourse AddClassTeacher(T_InstanceOfCourse instanceOfCourse)
 {
     try
     {
         using (dataContext = new ApplicationDbContext())
         {
             dataContext.Set <T_InstanceOfCourse>().Add(instanceOfCourse);
             dataContext.SaveChanges();
             return(instanceOfCourse);
         }
     }
     catch (Exception ex)
     {
         //TODO: guardar en api log
         throw;
     }
 }
Ejemplo n.º 2
0
        public async Task <ActionResult> addClass(InstanceOfCourseViewModel model)
        {
            var courseDal = new Course_DAL();

            if (ModelState.IsValid)
            {
                DateTime dateTime = DateTime.ParseExact(model.StartTime,
                                                        "hh:mm tt", CultureInfo.InvariantCulture);
                TimeSpan span  = dateTime.TimeOfDay;
                TimeSpan span2 = dateTime.AddHours(3).TimeOfDay;

                var newModel = new T_InstanceOfCourse
                {
                    InstanceOfCourseID = Guid.NewGuid(),
                    TeacherID          = User.Identity.GetUserId(),
                    Date             = model.Date,
                    StartTime        = span,
                    FinalTime        = span2,
                    CourseID         = Guid.Parse(model.CourseID),
                    CreateDate       = DateTime.Now,
                    ModificationDate = DateTime.Now,
                    LogicalErasure   = false
                };

                try
                {
                    var response = courseDal.AddClassTeacher(newModel);
                    if (response != null)
                    {
                        return(RedirectToAction("Courses"));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            var courses = courseDal.list();

            ViewBag.courses = courses.Select(i => new SelectListItem()
            {
                Text = i.Name, Value = i.CourseID.ToString()
            });

            return(View(model));
        }