public async Task <IActionResult> Edit(int id, [Bind("Name,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] ArticlesCategory articlesCategory) { if (id != articlesCategory.Id) { return(this.NotFound()); } if (this.ModelState.IsValid) { try { this.dataRepository.Update(articlesCategory); await this.dataRepository.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!this.ArticlesCategoryExists(articlesCategory.Id)) { return(this.NotFound()); } else { throw; } } return(this.RedirectToAction(nameof(this.Index))); } return(this.View(articlesCategory)); }
public ActionResult ArticlesCategoriesManage(string ArticlesCategoryAddName) { var newArticleCategory = new ArticlesCategory { Name = ArticlesCategoryAddName }; db.ArticlesCategories.Add(newArticleCategory); db.SaveChanges(); return(RedirectToAction("ArticlesCategoriesManage", "Backoffice")); //var articlesCategories = db.ArticlesCategories; //var VM = new ArticlesCategoriesManageViewModel { ArticleCategories = articlesCategories}; //return View(VM); }
protected override void TestMappings(PersistenceSpecification <Article> specification) { Assertion.NotNull(specification); var category = new ArticlesCategory("category.name"); specification.TransactionalSave(category); base.TestMappings(specification); specification.CheckProperty(mapping => mapping.Annotation, "annotation"); specification.CheckReference(mapping => mapping.Category, category); specification.CheckProperty(mapping => mapping.Image, "image"); }
public async Task <IActionResult> Create([Bind("Name,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] ArticlesCategory articlesCategory) { if (this.ModelState.IsValid) { await this.dataRepository.AddAsync(articlesCategory); await this.dataRepository.SaveChangesAsync(); return(this.RedirectToAction(nameof(this.Index))); } return(this.View(articlesCategory)); }
public ActionResult Add(FormCollection collection) { string title_az = Request.Form["title_az"]; string title_en = Request.Form["title_en"]; string excerpt_az = Request.Form["excerpt_az"]; string excerpt_en = Request.Form["excerpt_en"]; string content_az = Request.Form["content_az"]; string content_en = Request.Form["content_en"]; string category_id = Request.Form["category_id"]; string tags = Request.Form["tags[]"]; string status = Request.Form["status"]; string title_img_id = Request.Form["title_img_id"]; if (string.IsNullOrWhiteSpace(title_az) || string.IsNullOrWhiteSpace(title_en)) { viewArticles.ErrorMsg = "Title is required field! "; return(View(model: viewArticles)); } if (string.IsNullOrWhiteSpace(category_id)) { viewArticles.ErrorMsg = "Category is required field!"; return(View(model: viewArticles)); } Article article = new Article { title_az = title_az, title_en = title_en, excerpt_az = excerpt_az, excerpt_en = excerpt_en, content_az = content_az, content_en = content_en, status = Convert.ToByte(status) }; if (!string.IsNullOrWhiteSpace(title_img_id)) { article.title_img_id = Convert.ToInt32(title_img_id); } if (article.status == 1) { article.date = DateTime.Now; } db.Articles.Add(article); db.SaveChanges(); ArticlesCategory articlesCategory = new ArticlesCategory { article_id = article.id, category_id = Convert.ToInt32(category_id) }; db.ArticlesCategories.Add(articlesCategory); if (string.IsNullOrWhiteSpace(tags)) { List <string> tagsList = tags.Split(',').ToList(); foreach (string tag in tagsList) { ArticlesTag articlesTag = new ArticlesTag { article_id = article.id, tag_id = Convert.ToInt32(tag) }; db.ArticlesTags.Add(articlesTag); } } db.SaveChanges(); if (article.status == 0) { return(RedirectToAction("NonPublished")); } else { return(RedirectToAction("Published")); } }