public IActionResult Add(CategoryAddViewModel model) { if (ModelState.IsValid) { // Controlling the database exist category with same name var categoryNameControl = _categoryService.GetCategoryByName(model.Name); if (categoryNameControl != null) { TempData["Message"] = "Bu isimde bir kategori zaten kayıtlı !"; TempData["MessageState"] = "danger"; return(View(model)); } var category = new Category { Name = model.Name }; _categoryService.Add(category); TempData["Message"] = "Yeni kategori başarıyla eklendi !"; TempData["MessageState"] = "warning"; return(RedirectToAction("Categories", "Admin")); } TempData["Message"] = "Kategori ekleme işlemi başarısız oldu !"; TempData["MessageState"] = "danger"; return(View()); }
public IActionResult Add(CategoryAddViewModel VM, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { string categoryName = _textFormatter. RemoveDoubleSpaces(_textFormatter. CapitaliseFirstLetters(VM.CategoryName, false)); string description = VM.Description != null && VM.Description != "" ? _textFormatter. RemoveDoubleSpaces(VM.Description) : ""; Category newCategory = new Category() { CategoryName = categoryName, Description = description, ImageUrl = VM.ImageUrl, InUse = true }; _catService.Create(newCategory); return(RedirectToAction("SuccessfullyAdded", "Category")); } else { return(View(VM)); } }
public ActionResult AddCategory(CategoryAddViewModel model) { //model doğrulandı mı, entity de validation için yazılır. if (ModelState.IsValid) { if (model.Category.CategoryId != 0) { //update var category = new CategoryManager().Get(c => c.CategoryId == model.Category.CategoryId); category.CategoryDescription = model.Category.CategoryDescription; category.CategoryName = model.Category.CategoryName; //ilişkili nesenelerde onların idi leri set edilir. category.CategoryTypeId = model.Category.CategoryTypeId; new CategoryManager().Update(category); } else { //add //veritabanında veri olmadığı için bir şey getirilmiyor bu yüzden direkt bu şekilde yazılır new CategoryManager().Add(model.Category); } } else { ViewBag.Message = "Model yanlış"; return(View()); } return(RedirectToAction("ListCategory")); }
public ActionResult Create(CategoryAddViewModel newCategory) { try { using (var dbContext = new MvclibraryEntities()) { int?rootId = null; if (newCategory.SelectedCategoryId != null) { rootId = int.Parse(newCategory.SelectedCategoryId); } var category = new category { Name = newCategory.Name, RootCategoryId = rootId }; dbContext.Entry(category).State = EntityState.Added; dbContext.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception e) { return(View()); } }
public ActionResult AddCategory() { var obj = new CategoryAddViewModel(); obj.CategoryId = categoryId++; return(View(obj)); }
public void Add_ShouldCallCategoryServiceCreate() { // Arrange var categoryService = new Mock <ICategoryService>(); var identityMock = new Mock <IIdentity>(); var principalMock = new Mock <IPrincipal>(); principalMock.Setup(x => x.Identity).Returns(identityMock.Object); var httpContext = new Mock <HttpContextBase>(); httpContext.Setup(x => x.User).Returns(principalMock.Object); var contextMock = new Mock <ControllerContext>(); contextMock.Setup(x => x.HttpContext).Returns(httpContext.Object); var controller = new CategoriesController(categoryService.Object) { ControllerContext = contextMock.Object }; var model = new CategoryAddViewModel { Title = "title" }; // Act var result = controller.Add(model); // Assert categoryService.Verify(x => x.Create(It.IsAny <string>(), It.Is <string>(y => y == model.Title))); }
public ActionResult Create(CategoryAddViewModel model) { if (ModelState.IsValid) { var category = new Category() { Name = model.Name, Alias = model.Name.ToUrlSlug(), ParentId = model.ParentId, }; if (model.Image != null) { category.ImageMimeType = model.Image.ContentType; using (MemoryStream ms = new MemoryStream()) { model.Image.InputStream.Seek(0, SeekOrigin.Begin); model.Image.InputStream.CopyTo(ms); category.Image = ms.GetBuffer(); } } _unitOfWork.Categories.Add(category); _unitOfWork.Complete(); return(RedirectToAction("Index")); } model.Categories = new SelectList(_unitOfWork.Categories.GetAll(), "Id", "Name"); return(View(model)); }
public virtual PartialViewResult CreateCategory(CategoryAddViewModel model) { if (!ModelState.IsValid) { return(PartialView(viewName: MVC.admin.Shared.Views._ValidationSummery)); } var category = new Category(); if (model.Parent_Id > 0) { var rootCategory = _categoryService.GetById(Id: model.Parent_Id); category.Parent = rootCategory; } category.Name = model.Name; _categoryService.Create(category); if (_unitOfWork.SaveAllChanges() > 0) { return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel { Alert = AlertOperation.SurveyOperation(StatusOperation.SuccsessInsert), Status = AlertMode.success })); } else { return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel { Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning })); } }
public ActionResult Add(CategoryAddViewModel category) { if (!ModelState.IsValid) { category.Categories = this.categories.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.ParentCategoryId.ToString() }); return(this.View(category)); } var categoryToAdd = new Category() { Name = category.Name, ParentCategoryId = category.ParentCategoryId == null ? null : (int?)int.Parse(category.ParentCategoryId) }; using (var unitOfWork = this.unitOfWork()) { this.categories.Add(categoryToAdd); unitOfWork.Commit(); } return(this.RedirectToAction("Details/" + categoryToAdd.Id, "Categories")); }
public CategoryAddView() { InitializeComponent(); CategoryAddViewModel cateView = new CategoryAddViewModel(); BindingContext = cateView; }
public ActionResult AddCategory(CategoryAddViewModel newCategory) { try { if (!ModelState.IsValid) { return(View(newCategory)); } var addedCategory = m.AddCategory(newCategory); if (addedCategory == null) { return(View(newCategory)); } else { return(RedirectToAction("../SkillCategory/CategoriesDetails", new { id = addedCategory.CategoryId })); } } catch { return(View(newCategory)); } }
public ActionResult Add(CategoryAddViewModel model) { var category = _categoryService.Create(new Category { CategoryName = model.CategoryName }); return(RedirectToAction("Index")); }
public CategoryBaseViewModel AddCategory(CategoryAddViewModel newCategory) { var addedCategory = ds.Categories.Add(mapper.Map <CategoryAddViewModel, Category>(newCategory)); ds.SaveChanges(); return(addedCategory == null ? null : mapper.Map <Category, CategoryBaseViewModel>(addedCategory)); }
public UIElement GetAddView() { CategoryAddViewModel viewModel = new CategoryAddViewModel(); CategoryAddView view = new CategoryAddView(viewModel); viewModel.CategoryAdded += (s, e) => OnAdd(e.Data, viewModel); return(view); }
public ActionResult AddCategory() { CategoryAddViewModel model = new CategoryAddViewModel { Category = new Category() }; return(View(model)); }
// GET: Admin/Category/Create public ActionResult Create() { var model = new CategoryAddViewModel() { Categories = new SelectList(_unitOfWork.Categories.GetAll(), "Id", "Name") }; return(View(model)); }
public ActionResult Add() { var model = new CategoryAddViewModel(); model.Categories = this.categories.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.ParentCategoryId.ToString() }); return(this.View(model)); }
public IActionResult AddCategory(CategoryAddViewModel model) { db.Category.Add(new Category() { Parent_id = model.ParentId, Title = model.Title }); db.SaveChanges(); return(RedirectToAction("Categories", "Admin")); }
public IActionResult AddCategory([FromBody] CategoryAddViewModel model) { if (!String.IsNullOrEmpty(model.Description) && !String.IsNullOrEmpty(model.Title)) { PageCategory category = new PageCategory(); category.Title = model.Title; category.Description = model.Description; _context.Category.Add(category); _context.SaveChanges(); return(Json("ok")); } return(Json(model)); }
public ActionResult Add(CategoryAddViewModel model) { if (!this.ModelState.IsValid) { return(View(model)); } var userId = this.User.Identity.GetUserId(); this.categoryService.Create(userId, model.Title); return(RedirectToAction("Index")); }
public IActionResult Add(CategoryAddViewModel model) { if (ModelState.IsValid) { Category category = new Category() { CategoryName = model.CategoryName }; category.LimitState = true; _categoryService.Add(category); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <ActionResult> Add(CategoryAddViewModel model) { if (ModelState.IsValid) { db.CourseCategories.Add(new CourseCategory() { Name = model.Name, Desc = model.Desc }); await db.SaveChangesAsync(); return(RedirectToAction("Index", "Category")); } return(View(model)); }
public async Task <ActionResult> Edit(CategoryAddViewModel model) { if (ModelState.IsValid) { var category = await db.CourseCategories.FindAsync(model.Id); category.Name = model.Name; category.Desc = model.Desc; await db.SaveChangesAsync(); int id = category.Id; return(RedirectToAction("View", "Category", new { id = id })); } return(View(model)); }
public IActionResult Add() { foreach (var item in _categoryService.GetAll().Where(c => c.ParentId == "0")) { categoryList.Add(item); GetSubCategory(item.CategoryName, item.CategoryId); } var model = new CategoryAddViewModel { Category = new Category(), Categories = categoryList }; return(View(model)); }
public ActionResult Create() { using (var dbContext = new MvclibraryEntities()) { var s = dbContext.category.ToList(); var zvm = new CategoryAddViewModel(); zvm.CategoryList = s.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }); return(View(zvm)); } }
public ActionResult Add(CategoryAddViewModel vm) { var result = SaveAs(vm.Image, PlatformConfiguration.UploadedCategoryPath); if (result != null) { Command.Execute(new AddCategoryCommand { Icon = vm.Icon, Name = vm.Name, FileId = result.File.Id }); } return(RedirectToAction("Index")); }
public ActionResult AddCategory(int id = 0) { //Category i içeren yeni bir model class ı oluşturduk var model = new CategoryAddViewModel(); CategoryTypeManager categoryTypeManager = new CategoryTypeManager(); var categoryTypes = categoryTypeManager.GetAll(); ViewBag.CategoryTypes = categoryTypes; //model.Category dediğimizde null gelmemesi için model kısmında constructor unda new leme yapıyoruz if (id != 0) { var category = new CategoryManager().Get(c => c.CategoryId == id); model.Category = category; } return(View(model)); }
private void OnAdd(string categoryName, CategoryAddViewModel viewModel) { using (ICategoryController controller = factory.CreateCategoryController()) { ControllerMessage controllerMessage = controller.Add(categoryName); if (controllerMessage.IsSuccess) { viewModel.Name = String.Empty; Notify(); } else { MessageBox.Show(controllerMessage.Message); } } }
public ActionResult Edit(CategoryAddViewModel c) { try { using (var dbContext = new MvclibraryEntities()) { var s = dbContext.category.ToList(); var editCategory = dbContext.category.Where(b => b.Id == c.Id).FirstOrDefault(); editCategory.Name = c.Name; int?rootId = null; if (c.SelectedCategoryId != null) { rootId = int.Parse(c.SelectedCategoryId); } editCategory.RootCategoryId = rootId; dbContext.Entry(editCategory).State = EntityState.Modified; dbContext.SaveChanges(); } return(RedirectToAction("Index")); } catch (Exception e) { using (var dbContext = new MvclibraryEntities()) { var s = dbContext.category.ToList(); var editCategory = dbContext.category.Where(ce => ce.Id == c.Id).FirstOrDefault(); var zvm = new CategoryAddViewModel { Id = editCategory.Id, Name = editCategory.Name, SelectedCategoryId = editCategory.RootCategoryId.ToString() }; zvm.CategoryList = s.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }); return(View(zvm)); } } }
public IActionResult Add(CategoryAddViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var category = new Category { CategoryName = model.CategoryName }; _categoryRepository.AddCategory(category); model.StatusMessage = "New category added successfully!"; return(View(model)); }