Пример #1
0
        public ActionResult Add()
        {
            List <CategoryPathDTO> tempParentCategories = _categoryService.GetAllPaths(CurrentLanguage, CurrentWebsite);

            List <CategoryPathDTO> parentCategoriesDTO = new List <CategoryPathDTO>();

            foreach (var cat in tempParentCategories)
            {
                if (cat.Path.Count < 4)
                {
                    parentCategoriesDTO.Add(cat);
                }
            }

            Mapper.Initialize(c => c.CreateMap <CategoryPathDTO, AddCategoryPathVM>());

            List <AddCategoryPathVM> parentCategoriesVM = Mapper.Map <List <CategoryPathDTO>, List <AddCategoryPathVM> >(parentCategoriesDTO);

            AddCategoryVM model = new AddCategoryVM();

            model.Category         = new CategoryDetailsVm();
            model.ParentCategories = parentCategoriesVM;

            return(View("Addd", model));
        }
Пример #2
0
        public ActionResult AddCategory(AddCategoryVM cat)
        {
            if (ModelState.IsValid)
            {
                var category = Mapper.Map <CategoryEntity>(cat.Category);

                var parentCategory = db.Categories.Find(category.ParentId);

                if (parentCategory != null)
                {
                    var exist = parentCategory.Categories.Any(c => c.Name == cat.Category.Name);

                    if (exist)
                    {
                        ModelState.AddModelError("error_msg", "Current category exist in the parent category");
                        var cats = db.Categories.ToList();
                        cat.AllCategories = Mapper.Map <List <CategoryVM> >(cats);
                        return(View(cat));
                    }
                }
                db.Categories.Add(category);
                db.SaveChanges();

                ViewBag.Message = "Category Added succefully";
            }
            AddCategoryVM acVM = new AddCategoryVM();

            return(View(acVM));
        }
Пример #3
0
        public ActionResult Edit(AddCategoryVM vm)
        {
            if (ModelState.IsValid)
            {
                CategoryManegerDTO categoryDTO = new CategoryManegerDTO();
                Mapper.Initialize(c => c.CreateMap <CategoryDetailsVm, CategoryManegerDTO>());
                categoryDTO = Mapper.Map <CategoryDetailsVm, CategoryManegerDTO>(vm.Category);
                OperationDetails op = _categoryService.EditCategoryManager(categoryDTO);
                return(Json(new { Succedeed = op.Succedeed, message = op.Message }));
            }
            else
            {
                List <CategoryPathDTO> tempParentCategories = _categoryService.GetAllPaths(CurrentLanguage, Common.WebSites.Fashion);

                List <CategoryPathDTO> parentCategoriesDTO = new List <CategoryPathDTO>();

                foreach (var cat in tempParentCategories)
                {
                    if (cat.Path.Count < 3)
                    {
                        parentCategoriesDTO.Add(cat);
                    }
                }

                Mapper.Initialize(c => c.CreateMap <CategoryPathDTO, AddCategoryPathVM>());

                List <AddCategoryPathVM> parentCategoriesVM = Mapper.Map <List <CategoryPathDTO>, List <AddCategoryPathVM> >(parentCategoriesDTO);
                vm.ParentCategories = parentCategoriesVM;
                return(View(vm));
            }
        }
Пример #4
0
        public ActionResult Edit(long Id)
        {
            CategoryManegerDTO categoryDTO = _categoryService.GetCategoryManagerById(Id);

            List <CategoryPathDTO> tempParentCategories = _categoryService.GetAllPaths(CurrentLanguage, CurrentWebsite);
            List <CategoryPathDTO> parentCategoriesDTO  = new List <CategoryPathDTO>();

            foreach (var cat in tempParentCategories)
            {
                if (cat.Path.Count < 4)
                {
                    cat.CategoryId = cat.Path[cat.Path.Count - 1].Item1;
                    parentCategoriesDTO.Add(cat);
                }
            }

            Mapper.Initialize(c => c.CreateMap <CategoryPathDTO, AddCategoryPathVM>());

            List <AddCategoryPathVM> parentCategoriesVM = Mapper.Map <List <CategoryPathDTO>, List <AddCategoryPathVM> >(parentCategoriesDTO);
            SelectList list = new SelectList(parentCategoriesVM, "CategoryId", "PathStr", parentCategoriesVM[0]);

            Mapper.Initialize(c => c.CreateMap <CategoryManegerDTO, CategoryDetailsVm>());
            CategoryDetailsVm categoryVM = Mapper.Map <CategoryManegerDTO, CategoryDetailsVm>(categoryDTO);

            AddCategoryVM model = new AddCategoryVM();

            model.Category         = categoryVM;
            model.ParentCategories = parentCategoriesVM;


            return(View(model));
        }
Пример #5
0
 public ActionResult Create(AddCategoryVM model)
 {
     if (db.Service.CreateCategory(model))
     {
         return(View("Index"));
     }
     return(View(model));
 }
Пример #6
0
 public void AddNewCategory(AddCategoryVM model)
 {
     // Todo - fixa så att order kollas och ändras
     Category.Add(new Category
     {
         Order = Category.Max(c => c.Order) + 1,
         Title = model.CategoryTitle,
     });
     SaveChanges();
 }
Пример #7
0
        public IActionResult AddCategory(AddCategoryVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            context.AddNewCategory(model);

            return(RedirectToAction(nameof(Index)));
        }
Пример #8
0
        public ActionResult AddCategory()
        {
            ViewBag.Message = "Add category page.";

            AddCategoryVM acVM = new AddCategoryVM();
            //var entities = db.Categories.ToList();

            var cats = db.Categories;

            acVM.AllCategories = Mapper.Map <List <CategoryVM> >(cats);

            return(View(acVM));
        }
Пример #9
0
        public IActionResult Category([FromBody] AddCategoryVM categoryVm)
        {
            Category category = null;

            try
            {
                category             = _categoryService.Add(Mapper.Map <Category>(categoryVm));
                category.UserProfile = this.UserProfile;
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToInvariantString()));
            }
            return(Ok(JsonConvert.SerializeObject(Mapper.Map <CategoryVM>(category))));
        }
Пример #10
0
        public IActionResult AddCategory()
        {
            var model = new AddCategoryVM
            {
            };

            _database.Add(new AdminActivity
            {
                ActivityID     = 2,
                AdminID        = Int32.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)),
                DateOfActivity = DateTime.Now
            });
            _database.SaveChanges();

            return(View(model));
        }
 public IActionResult Add(AddCategoryVM candidateCategory)
 {
     if (candidateCategory == null || !ModelState.IsValid)
     {
         return(BadRequest());
     }
     try
     {
         var result = this._candidateCategoryService.Insert(candidateCategory.ToCandidateCategory());
         return(CreatedAtAction(nameof(Add), result));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Пример #12
0
        public ActionResult AddCategory(AddCategoryVM cat)
        {
            if (ModelState.IsValid)
            {
                var category = Mapper.Map <CategoryEntity>(cat.Category);

                db.Categories.Add(category);
                db.SaveChanges();

                ViewBag.Message = "Category Added succefully";
            }
            AddCategoryVM acVM = new AddCategoryVM();

            acVM.AllCategories = Mapper.Map <List <CategoryVM> >(db.Categories);

            return(View(acVM));
        }
 public bool CreateCategory(AddCategoryVM model)
 {
     try
     {
         obj.Categories.Add(new Category
         {
             CategoryName = model.CategoryName
         });
         if (obj.SaveChanges() > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #14
0
 public RedirectToActionResult AddCategory(AddCategoryVM categoryVm)
 {
     if (ModelState.IsValid)
     {
         Category category = null;
         try
         {
             category            = Mapper.Map <Category>(categoryVm);
             category.CreateBy   = GetProfile(this.User).Id;
             category.CreateDate = DateTime.Now;
             _categoryService.Add(category);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     return(RedirectToAction("Category"));
 }
Пример #15
0
        public IActionResult SaveCategory(AddCategoryVM model)
        {
            string uniquefileName = null;

            if (model.Image != null)
            {
                string uploadsFolder = Path.Combine(hosting.WebRootPath, "images");
                uniquefileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;
                string filePath = Path.Combine(uploadsFolder, uniquefileName);
                model.Image.CopyTo(new FileStream(filePath, FileMode.Create));
            }
            Category category = new Category
            {
                CategoryName = model.categoryName,
                ImageUrl     = uniquefileName
            };

            _Iproduct.AddCategory(category);
            return(Redirect("/Administration/Index"));
        }
Пример #16
0
 public static CandidateCategory ToCandidateCategory(this AddCategoryVM viewModel)
 => new CandidateCategory
 {
     Type = viewModel.Type
 };