public IActionResult Create(LessonModel model) { if (ModelState.IsValid) { var entity = new Lesson() { LessonName = model.LessonName, Description = model.Description, Images = model.Images }; //if (model.Images.Length > 0) //{ // entity.Images = model.Images.FileName; // var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", model.Images.FileName); // using (var stream = new FileStream(path, FileMode.Create)) // { // await model.Images.CopyToAsync(stream); // } //} _lessonService.Create(entity); return(RedirectToAction("LessonList")); } return(View(model)); }
public async Task <ActionResult <Lesson> > Create(LessonRequest lesson) { var result = await _lessons.Create(lesson, HttpContext.RequestAborted); if (result == null) { return(Conflict()); } return(result); }
public ActionResult Create(Lesson lesson) { try { lessonService.Create(lesson); return(RedirectToAction(nameof(Index))); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); return(View(lesson)); } }
public ActionResult Create(Lesson lesson, string courseId) { try { _lessonRepository.Create(lesson, courseId); return(RedirectToAction("Index", new { courseId = courseId })); } catch { return(View(lesson)); } }
public IActionResult Create([FromBody] LessonCreateModel model) { var lessonModel = _mapper.Map <Lesson>(model); try { lessonModel.UserId = GetUserId(); var lesson = _lessonService.Create(lessonModel); return(Ok(_mapper.Map <LessonModel>(lesson))); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public async Task <IActionResult> Create(LessonDTO model, IFormFile file) { var path = Path.Combine("Uploads", "DefaultPicture", "defaultLesson.png"); if (file != null) { var webRoot = Path.Combine("Uploads", "Documents"); path = Path.Combine(webRoot, file.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } } model.Resim = path; model.EkleyenId = Convert.ToInt32(User.Claims.Where(c => c.Type == ClaimTypes.Name).Select(c => c.Value) .SingleOrDefault()); model.Guid = Guid.NewGuid(); model.EklenmeZamani = DateTime.Now; model.Aktif = true; model.Silindi = false; var lessonId = _lessonService.Create(model); var tutorLesson = new TutorLessonDTO() { Guid = Guid.NewGuid(), Aktif = true, EklenmeZamani = DateTime.Now, KullaniciId = Convert.ToInt32(User.Claims.Where(c => c.Type == ClaimTypes.Name).Select(c => c.Value) .SingleOrDefault()), LessonId = lessonId, Silindi = false, EkleyenId = Convert.ToInt32(User.Claims.Where(c => c.Type == ClaimTypes.Name).Select(c => c.Value) .SingleOrDefault()) }; _tutorLessonService.Create(tutorLesson); var user = _kullaniciService.GetById(Convert.ToInt32(User.Claims.Where(c => c.Type == ClaimTypes.Name) .Select(c => c.Value) .SingleOrDefault())); return(RedirectToAction("GetTeacher", new RouteValueDictionary(new { controller = "Account", action = "GetTeacher", guid = user.Guid }))); }
public async Task <IActionResult> CreateLesson([FromBody] LessonForCreationDto model) { // maps resource to domain model var lesson = _mapper.Map <Lesson>(model); try { // calls lesson service to create a new lesson var lessonCreated = await _lessonService.Create(lesson, model.SubjectId); // maps domain model to resource // returns 200ok return(Ok(_mapper.Map <LessonDto>(lessonCreated))); } catch (Exception ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public IActionResult Create([Bind("Id,StudentId,TrainerId,DateTime,Hour,Minutes,IsCompleted", Prefix = "Data")] LessonDto lesson) { ResultHandler <LessonDto> resultHandler = new ResultHandler <LessonDto>(); if (ModelState.IsValid) { resultHandler = _lessonService.Create(lesson); if (!resultHandler.HasErrors) { return(RedirectToAction(nameof(Index))); } } ViewData["StudentId"] = new SelectList(_studentService.GetList().Data, "Id", "LastName"); ViewData["TrainerId"] = new SelectList(_trainerService.GetList().Data, "Id", "LastName"); ResultViewModel <LessonDto> lessonViewModel = AutoMapper.Mapper.Map <ResultHandler <LessonDto>, ResultViewModel <LessonDto> >(resultHandler); return(View(lessonViewModel)); }