Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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"));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 8
0
        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
                }));
            }
        }
Ejemplo n.º 9
0
        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"));
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        public UIElement GetAddView()
        {
            CategoryAddViewModel viewModel = new CategoryAddViewModel();
            CategoryAddView      view      = new CategoryAddView(viewModel);

            viewModel.CategoryAdded += (s, e) => OnAdd(e.Data, viewModel);

            return(view);
        }
Ejemplo n.º 15
0
        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));
        }
Ejemplo n.º 17
0
        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));
        }
Ejemplo n.º 18
0
        public IActionResult AddCategory(CategoryAddViewModel model)
        {
            db.Category.Add(new Category()
            {
                Parent_id = model.ParentId,
                Title     = model.Title
            });

            db.SaveChanges();

            return(RedirectToAction("Categories", "Admin"));
        }
Ejemplo n.º 19
0
 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"));
        }
Ejemplo n.º 21
0
 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));
 }
Ejemplo n.º 22
0
        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));
        }
Ejemplo n.º 23
0
        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));
        }
Ejemplo n.º 25
0
        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));
            }
        }
Ejemplo n.º 26
0
        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"));
        }
Ejemplo n.º 27
0
        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));
        }
Ejemplo n.º 28
0
        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);
                }
            }
        }
Ejemplo n.º 29
0
        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));
                }
            }
        }
Ejemplo n.º 30
0
        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));
        }