public ActionResult Create(CourseInputModel model) { if (model != null && this.ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var newArticle = this.Mapper.Map<Course>(model); var imageUploader = new ImageUplouder(); var images = new HashSet<Image>(); string folderPath = Server.MapPath(WebConstants.ImagesMainPathMap + currentUserId); if (model.Files != null && model.Files.Count() > 0) { foreach (var file in model.Files) { if (file != null && (file.ContentType == WebConstants.ContentTypeJpg || file.ContentType == WebConstants.ContentTypePng) && file.ContentLength < WebConstants.MaxImageFileSize) { images.Add(imageUploader.UploadImage(file, folderPath, currentUserId)); } } } var trainer = this.users.UserById(currentUserId).FirstOrDefault(); newArticle.Trainers.Add(trainer); var result = this.courses.Create(newArticle); return this.RedirectToAction("Course", "School", new { area = "", id = result }); } return this.View(model); }
public ActionResult Edit(CourseInputModel model) { if (model != null && ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var updatedArticle = this.Mapper.Map<Course>(model); var imageUploader = new ImageUplouder(); var images = new HashSet<Image>(); string folderPath = Server.MapPath(WebConstants.ImagesMainPathMap + currentUserId); if (model.Files != null && model.Files.Count() > 0) { foreach (var file in model.Files) { if (file != null && (file.ContentType == WebConstants.ContentTypeJpg || file.ContentType == WebConstants.ContentTypePng) && file.ContentLength < WebConstants.MaxImageFileSize) { images.Add(imageUploader.UploadImage(file, folderPath, currentUserId)); } } } images.ForEach(x => updatedArticle.Images.Add(x)); this.courses.Update(model.Id, updatedArticle); return this.RedirectToAction("Course", "School", new { area = "", id = model.Id }); } return this.View(model); }
public ActionResult Create(ArticleInputModel model) { if (model != null && ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var newArticle = this.Mapper.Map<Article>(model); var imageUploader = new ImageUplouder(); var images = new HashSet<Image>(); string folderPath = Server.MapPath(WebConstants.ImagesMainPathMap + currentUserId); if (model.Files != null && model.Files.Count() > 0) { foreach (var file in model.Files) { if (file != null && (file.ContentType == WebConstants.ContentTypeJpg || file.ContentType == WebConstants.ContentTypePng) && file.ContentLength < WebConstants.MaxImageFileSize) { images.Add(imageUploader.UploadImage(file, folderPath, currentUserId)); } } } newArticle.Type = ArticleType.Design; newArticle.AuthorId = currentUserId; newArticle.Images = images; var result = this.articles.Create(newArticle); return this.RedirectToAction("Details", "Design", new { area = "", id = result }); } return this.View(model); }