public IActionResult Create(Article postedObject) { if (_articleService.Create(postedObject)) { return(RedirectToAction("Index")); } return(View(postedObject)); }
public async Task <ActionResult <Article> > Create(Article article) { if (await _articleService.TitleExists(article.Title)) { return(Conflict()); } await _articleService.Create(article); return(CreatedAtRoute("GetArticle", new { id = article.Id }, article)); }
public ActionResult Create(ArticleViewModel item, string hashTags) { if (!ModelState.IsValid) { return(View(item)); } // Validation of unique field Title if (!ArticleService.Exists(i => i.Title == item.Title)) { item.Id = Guid.NewGuid(); } else { ViewBag.error = "Such title is exists!"; return(View(item)); } var tagTitlesList = hashTags.Split(' ').ToList(); var tagList = tagTitlesList.Select(tagTitle => new TagViewModel { Title = tagTitle }).ToList(); ArticleService.Create(item, tagList); return(RedirectToAction("Index")); }
public ActionResult Create(ArticleInfo articleInfo) { bool errors = false; bool isAdd = articleInfo.Id == 0 ? true : false; if (articleInfo.CategoryId == 0) { errors = true; ModelState.AddModelError("CAT", "Please select the category"); } if (string.IsNullOrEmpty(articleInfo.Title)) { errors = true; ModelState.AddModelError("TITLT", "Please enter a title "); } if (!errors && ModelState.IsValid) { ArticleService.Create(articleInfo); if (isAdd) { ViewBag.Msg = "Success.Continue?【<a href=\"create\">Yes</a>】 【<a href=\"list\">No</a>】"; } else { ViewBag.Msg = "Success.Continue?【<a href=\"create\">Yes</a>】 【<a href=\"list\">No</a>】"; } } return(View(articleInfo)); }
public ActionResult <Article> CreateArticle([FromBody] JObject jArticle) { var article = jArticle.ToObject <Article>(); _articleService.Create(article); return(article); }
static void TestEdit() { using var context = new DbContextFactory().CreateDbContext(); var unitOfWork = CreateUnitOfWork(context); var productService = new ProductService(unitOfWork); var articleService = new ArticleService(unitOfWork); var product = new Product { Name = "Test", Description = "Test", Manufacturer = "Test", Publisher = "Test", RentalExpiresAfterDays = 10 }; var createdProduct = productService.Create(product); var article = new Article { ProductId = createdProduct.Id, Status = ArticleStatus.Normal }; var createdArticle = articleService.Create(article); var updateStatusResult = articleService.UpdateStatus(createdArticle.Id, ArticleStatus.Broken); productService.Remove(createdProduct.Id); }
public ActionResult Create(ArticleInfo articleInfo) { bool errors = false; bool isAdd = articleInfo.Id == 0 ? true : false; if (articleInfo.CategoryId == 0) { errors = true; ModelState.AddModelError("CAT", "请选择分类"); } if (string.IsNullOrEmpty(articleInfo.Title)) { errors = true; ModelState.AddModelError("TITLT", "请输入文章标题"); } if (!errors && ModelState.IsValid) { ArticleService.Create(articleInfo); if (isAdd) { ViewBag.Msg = "添加成功!是否继续?【<a href=\"create\">是</a>】 【<a href=\"list\">否</a>】"; } else { ViewBag.Msg = "修改成功!是否继续?【<a href=\"create\">是</a>】 【<a href=\"list\">否</a>】"; } } return(View(articleInfo)); }
static void TestRemove() { using var context = new DbContextFactory().CreateDbContext(); var unitOfWork = CreateUnitOfWork(context); var productService = new ProductService(unitOfWork); var articleService = new ArticleService(unitOfWork); var customerService = new CustomerService(unitOfWork); var orderService = new OrderService(unitOfWork); var orderLineService = new OrderLineService(unitOfWork); var customer = customerService.Create(new Customer { FirstName = "Test", LastName = "Test", Email = "*****@*****.**" }); var product = productService.Create(new Product { Name = "Test", Description = "Test", Manufacturer = "Test", Publisher = "Test", RentalExpiresAfterDays = 10 }); var article = articleService.Create(new Article { ProductId = product.Id, Status = ArticleStatus.Normal }); var order = orderService.Create(customer.Id); var orderLine = orderLineService.Rent(order.Id, article.Id); var deleteResult = customerService.Remove(product.Id); }
public ActionResult Create(ArticleViewModel article) { var dtoModel = _modelsMapper.Map <ArticleViewModel, ArticleDTO>(article); _articleService.Create(dtoModel, article.TagsId); _articleService.Save(); return(RedirectToAction("Index")); }
public ArticleIdResponse Create(CreateArticleRequest createArticleRequest) { var(title, content, authorId) = createArticleRequest; var articleId = _articleService.Create(authorId, title, content); return(new ArticleIdResponse(articleId)); }
public ActionResult Create([Bind(Include = "id,firm_id,name,amount,price,tax")] article article) { if (ModelState.IsValid) { _articleService.Create(article); return(RedirectToAction("Index")); } ViewBag.firm_id = new SelectList(_firmService.GetAll(), "id", "name"); return(View(article)); }
public async Task Create_CreatesArticle() { //Arrange var dummyArticle = TestHelper.DummyArticles(1).Single(); _mockArticleRepository.Setup(repo => repo.Create(dummyArticle)).Returns(Task.CompletedTask); //Act await _articleService.Create(dummyArticle); //Assert Assert.Pass(); }
public void ArticleCreate() { Article article = new Article(); article.ArticleID = Guid.NewGuid().ToString(); article.Title = "Title"; article.Content = "Content"; article.CreateAt = DateTime.Now; articleService.Create(article); Article articleResult = articleService.GetArticleById(article.ArticleID); Assert.IsNotNull(articleResult); }
public void CreateArticleShouldThrowExceptionWithEmptyAuthorId() { // Arrange var db = Tests.GetDatabase(); var articleService = new ArticleService(db); // Act Action act = () => articleService.Create(ArticleTitle, ArticleContent, string.Empty); //var result = Record.Exception(act); xunit feature // Assert act .Should().ThrowExactly <InvalidOperationException>().WithMessage(InvalidInsertedData); }
public ActionResult Create(ActicleViewModel model, FormCollection fc) { model.ParentCategory = cate.AllList(); if (ModelState.IsValid) { model.Article.CreateBy = User.Identity.Name; var u = service.Create(model.Article); return(RedirectToAction("Index")); } model.ParentCategory = db.Categories.Where(c => c.ParentId == 0); return(View(model)); }
public ActionResult Create(ArticleModel articleModel) { if (ModelState.IsValid) { articleModel.ArticleID = Guid.NewGuid().ToString(); articleModel.CreateAt = DateTime.Now; articleModel.UpdateAt = DateTime.Now; string userID = HttpContext.Session["UserID"] as string; articleModel.UserID = userID; Article article = articleModel.ToEntity(); articleCRUD.Create(article); return(RedirectToAction("Index")); } articleModel.CategorySelectItems = getCateGorys(); return(View(articleModel)); }
public void CreateArticleShouldReturnTheCorrectResult() { // Arrange var db = Tests.GetDatabase(); var articleService = new ArticleService(db); // Act var authorFakeId = Guid.NewGuid().ToString(); articleService.Create(ArticleTitle, ArticleContent, authorFakeId); var result = db.Articles.FirstOrDefault(); // Assert result.Title .Should().Be(ArticleTitle); }
public void CreateArticleShouldReturnCorrectData() { Category category = new Category(); category.Id = 1; category.Name = "TestCategory"; Mock <ICategoryService> categoryService = new Mock <ICategoryService>(); categoryService .Setup(x => x.ExistsByName(It.IsAny <string>())) .Returns(false); categoryService .Setup(x => x.Create(It.IsAny <CategoryDTO>())) .Callback(() => { this.context.Categories.Add(category); this.context.SaveChanges(); }); categoryService .Setup(x => x.GetAllCategories(It.IsAny <List <string> >())) .Returns(new List <Label>() { category }); User user = new User() { Id = 1, UserName = "******" }; this.context.Users.Add(user); this.context.SaveChanges(); ArticleService articleService = new ArticleService(this.context, categoryService.Object); articleService.Create(new ArticleDTO() { Topic = "Vocab", Content = "Sent", Categories = "TestLabel" }, user); Assert.AreEqual(1, this.context.Articles.ToList().Count); Assert.AreEqual("Con", this.context.Articles.First().Content); }
public ActionResult Create(Article article) { try { if (ModelState.IsValid) { var articleService = new ArticleService(); articleService.Create(article); return RedirectToAction("Index"); } return View(); } catch { return View(); } }
public ActionResult <Article> Create(Article article) { var user = _userService.GetDtoByName(article.user.Name); if (user == null) { return(NotFound(new { message = "Usuário não encontrado" })); } article.user = user; var result = _articleService.Create(article); if (result != "Sucesso") { return(NotFound(new { message = result })); } return(CreatedAtRoute("GetArticle", new { id = article.Id.ToString() }, article)); }
public async Task <ActionResult> Create(ArticleCreateViewModel model) { try { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(User.Identity.GetUserName()); _articleSvc.Create(model, user.Id); _articleSvc.Save(); return(RedirectToAction("Index")); } return(View()); } catch { return(View()); } }
public ActionResult NewPost(string tabId, int parentId, string backendActionCode, bool?boundToExternal) { var data = ArticleService.NewForSave(parentId); var model = ArticleViewModel.Create(data, tabId, parentId, boundToExternal); TryUpdateModel(model); model.Validate(ModelState); if (ModelState.IsValid) { try { model.Data = ArticleService.Create(model.Data, backendActionCode, boundToExternal, HttpContext.IsXmlDbUpdateReplayAction()); // ReSharper disable once PossibleInvalidOperationException PersistFromId(model.Data.Id, model.Data.UniqueId.Value); PersistResultId(model.Data.Id, model.Data.UniqueId.Value); var union = model.Data.AggregatedArticles.Any() ? model.Data.FieldValues.Union(model.Data.AggregatedArticles.SelectMany(f => f.FieldValues)) : model.Data.FieldValues; foreach (var fv in union.Where(f => new[] { FieldExactTypes.O2MRelation, FieldExactTypes.M2MRelation, FieldExactTypes.M2ORelation }.Contains(f.Field.ExactType))) { AppendFormGuidsFromIds($"field_{fv.Field.Id}", $"field_uniqueid_{fv.Field.Id}"); } return(Redirect("Properties", new { tabId, parentId, id = model.Data.Id, successfulActionCode = backendActionCode, boundToExternal })); } catch (ActionNotAllowedException nae) { ModelState.AddModelError("OperationIsNotAllowedForAggregated", nae); return(JsonHtml("Properties", model)); } } return(JsonHtml("Properties", model)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; Article article = new Article() { Author = context.Session["CurrentUser"].ToString(), Title = context.Request["articleTitle"].ToString(), Content = HttpUtility.UrlDecode(context.Request["articleContent"].ToString()), CreateTime = DateTime.Now }; if (ArticleService.Create(article)) { context.Response.Write("ok"); } else { context.Response.Write("error"); } }
public void ArticleCreate() { ArticleService articleCRUD = new ArticleService(); Article article = new Article(); article.ArticleID = Guid.NewGuid().ToString(); article.Title = ".Net MVC学习"; article.Content = ".Net MVC学习,.Net MVC学习,.Net MVC学习,.Net MVC学习,.Net MVC学习,.Net MVC学习,.Net MVC学习,.Net MVC学习,.Net MVC学习,.Net MVC学习,.Net MVC学习"; article.CreateAt = DateTime.Now; article.Disc = "第一次学习好紧张"; article.Notes = "asd"; User user = new User(); user.UserID = "1f1c4189-3792-4a91-8d08-c0d04e18a0ae"; article.user = user; Category category = new Category(); category.CategoryID = "46ed952b-ec26-4bb9-a544-13a8d78dabf3"; article.category = category; articleCRUD.Create(article); }
public ActionResult CreateBasic(BasicViewModel Vmodel, HttpPostedFileBase[] files) { int article_id = 0; if (ModelState.IsValid) { var customer = _customerService.getCustomerById(Vmodel.customer_id); if (customer == null) { throw new InvalidOperationException("Cliente no encontrado"); } Mapper.CreateMap <BasicViewModel, model>(); var entity = Mapper.Map <BasicViewModel, model>(Vmodel); article_id = _articleService.Create(entity); addResources(article_id, files); } return(RedirectToAction("model", new { id = article_id })); }
public IActionResult CreateArticle([FromBody] CreateUpdateArticleRequest request) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } if (user.Role == UserRole.Client) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } if (ArticleService.IsArticleExist(request.Title)) { return(BadRequest(new ResponseModel { Success = false, Message = "Статья с таким названием уже существует" })); } var specialist = SpecialistService.GetSpecialistFromUser(user); if (specialist == null) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var previewImage = FileService.Get(request.PreviewImageID); if (previewImage == null) { return(NotFound(new ResponseModel { Success = false, Message = "Изображение не найдено" })); } if (request.ShortText.Length > 65535) { return(BadRequest(new ResponseModel { Success = false, Message = "Слишком длинный текст превью" })); } var article = new Article { Title = request.Title, ShortText = request.ShortText, Text = Encoding.UTF8.GetBytes(request.Text), Image = previewImage, Author = specialist, Date = DateTime.UtcNow, ModerationStatus = ArticleModerationStatus.New }; ArticleService.Create(article); var articlePublish = new ArticlePublish { Article = article, Status = ArticleModerationStatus.New }; ArticlePublishService.Create(articlePublish); return(Ok(new DataResponse <ArticleViewModel> { Data = new ArticleViewModel(article) })); }
public ActionResult <ArticleInfo> Create(ArticleInfo article) { _articleService.Create(article); return(CreatedAtRoute("GetArticle", new { id = article.Id.ToString() }, article)); }
public IActionResult Post(GetArticleView article) { articleService.Create(article); return(Ok(article)); }
public IActionResult Create(ArticleDto article) { return(new JsonResult(_articleService.Create(article))); }
public async Task <ActionResult <Article> > Create(Article article) { articleService.Create(article); return(CreatedAtAction(nameof(GetById), new { id = article.Id }, article)); }
public ActionResult <Article> Create(Article article) { _ArticleService.Create(article); return(CreatedAtRoute("GetBook", new { id = article.Id.ToString() }, article)); }