Beispiel #1
0
        public async Task <ActionResult> Add(PresentationAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                var file         = model.Presentation;
                var presentation = new Presentation()
                {
                    Name = model.Name, Order = 1, Course = db.Courses.Find(model.CourseId)
                };
                db.Presentations.Add(presentation);
                await db.SaveChangesAsync();

                int id   = presentation.Course.Id;
                var path = AddCourseFile(file, "presentation", "Presentations", id);
                if (path != null)
                {
                    presentation.Path = path;
                    await db.SaveChangesAsync();
                }
                return(RedirectToAction("View", "Course", new { id = model.CourseId }));
            }
            return(View(model));
        }
Beispiel #2
0
        public async Task <ActionResult> Edit(PresentationAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                var presentation = await db.Presentations.FindAsync(model.Id);

                if (presentation == null)
                {
                    return(View("Error"));
                }
                presentation.Name = model.Name;
                var file = model.Presentation;
                var path = AddCourseFile(file, "presentation", "Presentations", presentation.Course.Id);
                if (path != null)
                {
                    presentation.Path = path;
                }
                await db.SaveChangesAsync();

                return(RedirectToAction("View", "Course", new { id = model.CourseId }));
            }
            return(View(model));
        }