public async Task <IActionResult> Create([Bind("Id, Title, Content, Url, ImageFile")] ArticleInputModel model) { if (!this.ModelState.IsValid) { return(this.View()); } var wwwRootPath = this.webHostEnvironment.WebRootPath; var fileName = Path.GetFileNameWithoutExtension(model.ImageFile.FileName); var extension = Path.GetExtension(model.ImageFile.FileName); model.Url = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; var path = Path.Combine(wwwRootPath + "/img/art/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await model.ImageFile.CopyToAsync(fileStream); } var userId = this.userManager.GetUserId(this.HttpContext.User); var article = this.mapper.Map <Article>(model); article.Date = DateTime.UtcNow; article.UserId = userId; this.articles.Create(article); return(this.RedirectToAction("Index", "Home")); }
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)); }
public ActionResult Edit(ArticleInputModel model) { if (model != null && ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var updatedArticle = 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.Any()) { 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.articles.Update(model.Id, updatedArticle); return(this.RedirectToAction("Details", "Design", 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); }
public ActionResult Update(int id) { var artCatSrv = IoC.Resolve <IArticleCategoryService>(); var artSrv = IoC.Resolve <IArticleService>(); var tagSrv = IoC.Resolve <ITagService>(); var model = new ArticleInputModel(); var articleModel = artSrv.GetByKey(id); var catModel = artCatSrv.GetByKey(articleModel.CatId); model.ArticleModel = articleModel; model.ParentCatId = catModel.ParentId; model.ParentCats = artCatSrv.GetParents(); model.CatId = articleModel.CatId; model.ChildCats = artCatSrv.GetChilds(catModel.ParentId); var lstTag = new List <Tag>(); if (!string.IsNullOrEmpty(articleModel.Tags)) { var str = articleModel.Tags.Split(','); foreach (var item in str.ToList()) { var key = StringUtil.UnsignToString(item); lstTag.Add(tagSrv.GetByKey(key)); } model.Tags = lstTag; } return(View(model)); }
public bool Create(ArticleInputModel model, string userId) { try { var article = Mapper.Map <Article>(model); article.AuthorId = userId; article.ReadersCount = 0; this.Data.Articles.Add(article); this.Data.SaveChanges(); this.PhotoService.UploadCoverPhoto(model.CoverPhoto, article.Id); if (model.ArticlePhotos != null && model.ArticlePhotos != null) { foreach (var photo in model.ArticlePhotos) { var photoId = this.PhotoService.UploadPhoto(photo, article.Id); var dbPhoto = this.PhotoService.GetDbPhoto(photoId); article.Photos.Add(dbPhoto); } this.Data.SaveChanges(); } return(true); } catch (Exception e) { return(false); } }
private Article ArticleFromInputModelNew(ArticleInputModel model) { return(new Article { Body = model.Body, Title = model.Title }); }
public ActionResult Create() { var model = new ArticleInputModel(); ViewBag.Categories = this.DropDownListService.GetCategoriesList(); return(this.View(model)); }
public ActionResult Destroy([DataSourceRequest]DataSourceRequest request, ArticleInputModel model) { if (this.ModelState.IsValid && model != null) { this.articles.Destroy(model.Id, null); } return this.GridOperationObject(model, request); }
public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ArticleInputModel model) { if (this.ModelState.IsValid && model != null) { this.articles.Destroy(model.Id, null); } return(this.GridOperationObject(model, request)); }
public ActionResult CreateNew(int?catParentId, int?catId) { var artCatSrv = IoC.Resolve <IArticleCategoryService>(); var model = new ArticleInputModel(); var articleModel = new Arcticle(); model.ArticleModel = articleModel; model.ParentCatId = catParentId; model.ParentCats = artCatSrv.GetParents(); model.CatId = catId; model.ChildCats = artCatSrv.GetChilds(catParentId); return(View(model)); }
public ActionResult Create(ArticleInputModel model) { if (ModelState.IsValid) { var created = this.ArticleService.Create(model, this.GetUserId()); if (created) { return(this.Redirect("~/")); } } ViewBag.Categories = this.DropDownListService.GetCategoriesList(); return(this.View(model)); }
public ActionResult Update([DataSourceRequest] DataSourceRequest request, ArticleInputModel model) { if (model != null && this.ModelState.IsValid) { var updated = this.Mapper.Map <Article>(model); updated.Images = null; this.articles.Update(model.Id, updated); return(this.GridOperationObject(model, request)); } return(null); }
public ActionResult Update([DataSourceRequest]DataSourceRequest request, ArticleInputModel model) { if (model != null && this.ModelState.IsValid) { var updated = this.Mapper.Map<Article>(model); updated.Images = null; this.articles.Update(model.Id, updated); return this.GridOperationObject(model, request); } return null; }
public ActionResult Create(ArticleInputModel model) { if (this.ModelState.IsValid) { var userId = this.User.Identity.GetUserId(); var article = this.Mapper.Map<Article>(model); article.CreatorId = userId; this.articles.Add(article); return this.RedirectToAction("Index", "AllArticles"); } return this.View(model); }
//для уже существующих объектов. , нет работы с картинками private bool FillArticleFromInputModelEdit(Article baseObj, ArticleInputModel newObj) { bool changed = false; if (baseObj.Body != newObj.Body) { baseObj.Body = newObj.Body; changed = true; } if (baseObj.Title != newObj.Title) { baseObj.Title = newObj.Title; changed = true; } return(changed); }
public ActionResult Create([DataSourceRequest]DataSourceRequest request, ArticleInputModel model) { if (model != null && this.ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var newArticle = this.Mapper.Map<Article>(model); newArticle.AuthorId = currentUserId; var modelId = this.articles.Create(newArticle); model.Id = modelId; model.AuthorId = currentUserId; model.AuthorName = this.UserProfile.UserName; return this.GridOperationObject(model, request); } return null; }
public ActionResult Create([DataSourceRequest] DataSourceRequest request, ArticleInputModel model) { if (model != null && this.ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var newArticle = this.Mapper.Map <Article>(model); newArticle.AuthorId = currentUserId; var modelId = this.articles.Create(newArticle); model.Id = modelId; model.AuthorId = currentUserId; model.AuthorName = this.UserProfile.UserName; return(this.GridOperationObject(model, request)); } return(null); }
public async Task <IActionResult> Create(ArticleInputModel model) { if (!this.ModelState.IsValid) { return(this.View()); } var isSuccessfulCreated = await this._articleService.CreateAsync(model); if (isSuccessfulCreated) { TempData[GlobalConstants.TempDataSuccessMessageKey] = GlobalConstants .ArticleMessage .CreateArticleSuccess; } else { TempData[GlobalConstants.TempDataErrorMessageKey] = GlobalConstants.WrongMessage; } return(View()); }
public async Task <IActionResult> Create(ArticleInputModel articleInputModel) { if (!this.ModelState.IsValid) { return(this.View(articleInputModel)); } var category = await this._categoryService.GetById(articleInputModel.CategoryId); if (category == null) { this.ModelState.AddModelError(string.Empty, "Invalid category selected."); return(this.View(articleInputModel)); } articleInputModel.CreatorId = await this.GetLoggedUserId(); await this._articleService.Create(articleInputModel); this.TempData.AddSerialized(WebConstants.AlertKey, new Alert(AlertType.Success, string.Format(DalConstants.SuccessMessage, "created", "article"))); return(this.RedirectToAction(nameof(Search))); }
public ActionResult CreateNew(Arcticle artModel, int?catParentId, int CatId, string[] tags) { var artSrv = IoC.Resolve <IArticleService>(); var artCatSrv = IoC.Resolve <IArticleCategoryService>(); var tagSrv = IoC.Resolve <ITagService>(); var lstExisted = new List <Tag>(); var lstNotExisted = new List <Tag>(); artCatSrv.BeginTran(); try { if (tags.Length > 0) { var map = tags.Distinct().ToDictionary(x => StringUtil.UnsignToString(x)); foreach (var item in map) { var flag = tagSrv.CheckTitleContain(item.Key); if (!flag) { var tagEntity = new Tag(); tagEntity.TagTitle = item.Key; tagEntity.TagName = item.Value; tagEntity.CreateBy = CurrentInstance.Instance.CurrentUser.UserName; tagEntity.CreateDate = DateTime.Now; tagEntity.Status = true; tagSrv.CreateNew(tagEntity); tagSrv.CommitChange(); lstNotExisted.Add(tagEntity); } else { lstExisted.Add(tagSrv.GetByKey(item.Key)); } } var lstTag = lstExisted.Union(lstNotExisted); artModel.Tags = string.Join(",", lstTag.Select(n => n.TagName)); } artModel.CreateBy = CurrentInstance.Instance.CurrentUser.UserName; artModel.CreateDate = DateTime.Now; artModel.URL = "/" + UnsignToString(artModel.Name); artSrv.CreateNew(artModel); artSrv.CommitChange(); artSrv.CommitTran(); AlertSuccess(InfoString.CREATE_SUCCESSFULL); return(RedirectToAction("Index")); } catch (Exception ex) { artSrv.RollbackTran(); LogError(ex); var model = new ArticleInputModel(); var articleModel = artModel; model.ArticleModel = articleModel; var map = tags.Distinct().ToDictionary(x => StringUtil.UnsignToString(x)); var lstTag = new List <Tag>(); foreach (var item in map) { var flag = tagSrv.CheckTitleContain(item.Key); if (!flag) { var tag = new Tag(); tag.TagTitle = item.Key; tag.TagName = item.Value; lstTag.Add(tag); } else { lstTag.Add(tagSrv.GetByKey(item.Key)); } } model.Tags = lstTag; model.ParentCatId = catParentId; model.ParentCats = artCatSrv.GetParents(); model.CatId = CatId; model.ChildCats = artCatSrv.GetChilds(catParentId); return(View(model)); } }
public ActionResult Edit(ArticleInputModel model) { if (model != null && ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var updatedArticle = 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.Any()) { 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.articles.Update(model.Id, updatedArticle); return this.RedirectToAction("Details", "Design", new { area = "", id = model.Id }); } return this.View(model); }