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)); }
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)); }
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)); } }
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)); }
public ActionResult Create(AddCategoryVM model) { if (db.Service.CreateCategory(model)) { return(View("Index")); } return(View(model)); }
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(); }
public IActionResult AddCategory(AddCategoryVM model) { if (!ModelState.IsValid) { return(View(model)); } context.AddNewCategory(model); return(RedirectToAction(nameof(Index))); }
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)); }
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)))); }
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)); } }
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; } }
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")); }
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")); }
public static CandidateCategory ToCandidateCategory(this AddCategoryVM viewModel) => new CandidateCategory { Type = viewModel.Type };