public ActionResult UpdateCategory(CategoryVM model) { //guncellencek kategori buraya gönderilir ve update edilir. if (ModelState.IsValid) { Category cat = db.Categories.FirstOrDefault(x => x.ID == model.ID); cat.Name = model.Name; cat.Description = model.Description; db.SaveChanges(); ViewBag.IslemDurum = 1; return(View()); } else { ViewBag.IslemDurum = 2; return(View()); } }
public static List <CategoryVM> GetCategoryVMs(string baseUrl, QuerySearch query = null) { var returnCats = QueryHelper.QueryList <Category>(query, "category"); var categoryVMs = new List <CategoryVM>(); foreach (var cat in returnCats) { var vm = new CategoryVM() { Name = cat.Name, Id = cat.Id, }; vm.SetDefaultLinks(baseUrl, "category", cat.Name); vm.Embed = new Embed(authors: AuthorCollection.GetAuthorEmbed(baseUrl, cat.AuthorIds), books: BookCollection.GetBookEmbed(baseUrl, cat.BookIds)); categoryVMs.Add(vm); } return(categoryVMs); }
private void InitializeModel() { this.Repository = new CategoriesRepository(); if (this.ModelId > 0) { this.Model = this.Repository.GetByID(this.ModelId); } else { this.Model = new CategoryVM(); } if (this.Model != null) { categoryVMBindingSource.DataSource = this.Model; } }
public ActionResult EditCategory(int id) { CategoryVM categoryVM = new CategoryVM(); using (BankDB bankDB = new BankDB()) { CategoriesDTO categoriesDTO = bankDB.Categories.Find(id); if (categoriesDTO == null) { return(Content("Категория не доступна")); } categoryVM = new CategoryVM(categoriesDTO); } return(View(categoryVM)); }
public ActionResult Categories() { IEnumerable <CategoryDTO> categoryList = _catalog.GetGeneralCategoryList(); IEnumerable <CategoryVM> categoryListVM = Enumerable.Empty <CategoryVM>(); List <CategoryVM> hilist = new List <CategoryVM>(); foreach (var i in categoryList) { CategoryVM buff = new CategoryVM(); buff.CategoryId = i.Id; buff.ParentCategoryId = i.ParentCategoryID; buff.CategoryName = i.Name; hilist.Add(buff); buff = null; } categoryListVM = hilist; return(View(categoryListVM)); }
public bool IsSameCategoryDetails(CategoryVM cat) { bool flag = false; var catid = db.CategoryMasters.Where(x => x.CategoryName == cat.CategoryName).Select(x => x.CategoryId).FirstOrDefault(); var parentid = db.CategoryMasters.Where(x => x.CategoryId == catid).Select(x => x.ParentCategoryId).FirstOrDefault(); if (catid == cat.CategoryId && parentid == cat.ParentCategoryId) { flag = true; } else { flag = false; } return(flag); }
public ActionResult SelectPolicyDocCategory() { var fullPath = Server.MapPath(@"~/PolicyDocuments"); var ops = new PolicyDocumentsOperations(); var model = new CategoryVM() { PolicyDocumentToAdd = new PolicyDocument() { Category = new Category() } }; var response = ops.GetAllCategories(fullPath); model.CreateCategoryList(response.Data); return(View(model)); }
public ActionResult Update(Guid?id) { if (id == null) { return(RedirectToAction("List", "Category", new { area = "Admin" })); } Category cat = _categoryService.GetById((Guid)id); CategoryVM model = new CategoryVM() { ID = cat.ID, Name = cat.Name, Description = cat.Description }; return(View(model)); }
public async Task <IActionResult> Index(int productPage = 1) { CategoryVM categoryVM = new CategoryVM() { Categories = await _unitOfWork.Category.GetAllAsync() }; var count = categoryVM.Categories.Count(); categoryVM.Categories = categoryVM.Categories.OrderBy(c => c.Name).Skip((productPage - 1) * 2).Take(2).ToList(); categoryVM.PagingInfo = new PagingInfo { CurrentPage = productPage, ItemsPerPage = 2, TotalItems = count, urlParameter = "/Admin/Category/Index?productPage=:" }; return(View(categoryVM)); }
public ActionResult OnGet(int?id) { if (id != null) { var category = _repositoryWrapper.Category.GetById(id.Value); if (category == null) { return(NotFound()); } CategoryVM = _mapper.Map <CategoryVM>(category); return(Page()); } return(RedirectToPage("./Card")); }
public ActionResult CategoryAdd(int?id) { ViewBag.Id = id; ViewBag.ButtonName = "Save"; CategoryVM category = null; if (id != null) { ViewBag.ButtonName = "Update"; var categoryDto = adminManagerBll.GetCategoryById((int)id); if (categoryDto == null) { TempData["Error"] = "Category not exists."; return(View(category)); } category = MapperManager.GetMapperInstance().Map <CategoryVM>(categoryDto); } return(View(category)); }
public ActionResult AddCategory(CategoryVM model) { if (ModelState.IsValid) { Category cate = new Category();//instance aldık cate.Name = model.Name; cate.Description = model.Description; db.Categories.Add(cate); //categoriyeEkle db.SaveChanges(); //dbye gönder ViewBag.IslemDurum = 1; return(RedirectToAction("Index")); } else { ViewBag.IslemDurum = 2; return(View()); } }
public ActionResult UpdateCategory(CategoryVM model) { //güncellenecek kategori yakalanır ve yeni verilerie update edilir if (ModelState.IsValid) { Category category = db.Categories.FirstOrDefault(x => x.ID == model.ID); category.Name = model.Name; category.Description = model.Description; db.SaveChanges(); ViewBag.IslemDurum = 1; return(View()); } else { ViewBag.IslemDurum = 1; return(View()); } }
public IActionResult Edit(CategoryVM model, int?topcategories) { Category category = _bookcontext.Categories.FirstOrDefault(q => q.ID == model.CategoryID); category.CategoryName = model.CategoryName; if (topcategories == null) { category.TopCategory = 0; } else { category.TopCategory = topcategories; } _bookcontext.SaveChanges(); return(Redirect("/Admin/Category/")); }
public IActionResult Edit(CategoryVM vm) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorJson())); } else { vm.DoEdit(false); if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorJson())); } else { return(Ok(vm.Entity)); } } }
private void FormCategoryAdd_Load(object sender, EventArgs e) { if (id.HasValue) { try { CategoryVM view = service.Get(id.Value); if (view != null) { textBoxName.Text = view.Name; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public ActionResult Create(CategoryVM category) { if (ModelState.IsValid) { using (DbContextTransaction dbTran = _Context.Database.BeginTransaction()) { try { if (category.CategoryID == 0) { CategoryMaster insert = new CategoryMaster(); insert.CategoryName = category.CategoryName; insert.WhenEntered = System.DateTime.UtcNow; insert.WhenModified = System.DateTime.UtcNow; insert.IsActive = true; _Context.CategoriesMaster.Add(insert); _Context.SaveChanges(); dbTran.Commit(); } else { CategoryMaster update = _Context.CategoriesMaster.Find(category.CategoryID); update.CategoryName = category.CategoryName; update.WhenModified = System.DateTime.UtcNow; update.IsActive = true; _Context.Entry(update).State = EntityState.Modified; _Context.SaveChanges(); dbTran.Commit(); } } catch (Exception ex) { dbTran.Rollback(); throw ex; } } return(RedirectToAction("Index", "Category")); } else { return(View("Index", category)); } }
public IActionResult Edit(CategoryVM model, int categoryid) { Category category = _vatancontext.Categories.FirstOrDefault(x => x.ID == model.ID); if (ModelState.IsValid) { category.CategoryName = model.CategoryName; category.TopCategoryID = categoryid; _vatancontext.SaveChanges(); } else { return(View(model)); } return(RedirectToAction("Index", "Category")); }
public ActionResult Categories() { _categoryManager = CategoryManagerFactory.Create(); var response = _categoryManager.GetAllCategories(); if (response.Success == true) { var model = new CategoryVM { Category = new Categories(), CategoryList = response.Payload }; return(View(model)); } else { return(RedirectToAction("Index")); } }
public ActionResult UpdateCategory(CategoryVM model) { if (ModelState.IsValid) { Category category = db.Categorys.FirstOrDefault(m => m.ID == model.ID); category.Name = model.Name; category.Description = model.Description; db.SaveChanges(); ViewBag.IslemDurum = 1; return(RedirectToAction("Index")); } else { ViewBag.IslemDurum = 2; return(View()); } }
public ActionResult AddCategory(CategoryVM model) { if (ModelState.IsValid) { Category category = new Category(); category.Name = model.Name; category.ID = model.ID; db.Category.Add(category); db.SaveChanges(); ViewBag.islemDurum = 1; return(View()); } else { return(View()); ViewBag.islemDurum = 2; } }
public void InsertCategory(CategoryVM catvm) { CategoryMaster cat = new CategoryMaster(); if (catvm.ParentCategoryId == null) { catvm.ParentCategoryId = 0; } //JavaScriptSerializer serializer = new JavaScriptSerializer(); //var c=serializer.Serialize(catvm); //CategoryMaster cat =serializer.Deserialize<CategoryMaster>(c); cat.ParentCategoryId = catvm.ParentCategoryId; cat.CategoryName = catvm.CategoryName; cat.CategoryUrl = catvm.CategoryURL; // cat.CategoryIcon = catvm.CategoryIcon; cat.ShortDescription = catvm.ShortDescription; cat.MetaTitle = catvm.MetaTitle; cat.Keywords = catvm.Keywords; cat.LongDescription = catvm.LongDescription; cat.MetaDescription = catvm.MetaDescription; cat.IsActive = catvm.IsActive; cat.CreatedBy = catvm.CreatedBy; cat.CreatedDate = catvm.CreatedDate; try { db.CategoryMasters.Add(cat); db.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } //var categoryUrl = cat.CategoryUrl + "-" + cat.CategoryId; //cat.CategoryUrl = categoryUrl; //db.Entry(cat).State = EntityState.Modified; //db.SaveChanges(); }
public ActionResult UpdateCategory(CategoryVM model) { if (ModelState.IsValid) { Category category = db.Categories.FirstOrDefault(x => x.ID == model.ID); category.CategoryName = model.Name; category.Description = model.Description; db.SaveChanges(); ViewBag.islemDurum = 1; return(View()); } else { ViewBag.islemDurum = 2; return(View()); } }
protected virtual void PrepareAllCategoriesModel(CategoryVM model) { if (model == null) { throw new ArgumentNullException("model"); } model.AvailableCategories.Add(new System.Web.Mvc.SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Categories.Fields.Parent.None"), Value = "0" }); var categories = SelectListHelper.GetCategoryList(_categoryService, _languageService, _localizedEntityService, true); foreach (var c in categories) { model.AvailableCategories.Add(c); } }
public ActionResult AddCategory(CategoryVM model) { if (ModelState.IsValid) { Category category = new Category(); category.Name = model.Name; category.Description = model.Description; db.Categories.Add(category); db.SaveChanges(); ViewBag.IslemDurum = 1; return(View()); } else { ViewBag.IslemDurum = 2; return(View()); } }
public IActionResult Edit(CategoryVM categoryVM) { if (!ModelState.IsValid) { return(View(categoryVM) .ShowMessage(JConfirmMessageType.Warning, "Uyarı", "Bazı hatalar var")); } var categoryDto = Categories.GetCategoryById(categoryVM.Id, isTracking: false); categoryDto.Name = categoryVM.Name; categoryDto.IsActive = categoryVM.IsActive; Categories.UpdateCategory(categoryDto); return(RedirectToAction("List") .ShowMessage(JConfirmMessageType.Success, "İşlem başarılı", "Kategori başarıyla güncellendi")); }
public Register(MainVM main) { _main = main; FrequentCategory = new CategoryVM( new POS_ItemCategory { vCategoryShortDesc = "Frequent Items" }, this) { CategoryType = CategoryType.Frequent, IsSelected = true }; Categories.Insert(0, FrequentCategory); SelectCategoryCommand.Execute(FrequentCategory); UpdateFrequentCategory(); }
public IHttpActionResult Post(CategoryVM request) { if (request.Name.IsNullOrEmpty()) { return this.BadRequest("Category name must be supplied."); } Category category = new Category { Name = request.Name }; if (this.categoryService.CreateCategory(category)) { List<CategoryVM> categories = GetCategories(); return this.Created(categories); } return this.BadRequest(); }
public ActionResult Edit(CategoryVM model) { if (ModelState.IsValid) { if (rpcategory.Any(x => x.CategoryName.ToLower() == model.CategoryName.ToLower() && x.ID != model.ID)) { ViewBag.IslemDurum = EnumIslemDurum.IsimMevcut; } Category entity = rpcategory.Find(model.ID); entity.CategoryName = model.CategoryName; entity.UpdateDate = DateTime.Now; rpcategory.SaveChanges(); ViewBag.IslemDurum = EnumIslemDurum.Basarili; } else { ViewBag.IslemDurum = EnumIslemDurum.ValidationHata; } return(View(model)); }
private List <CategoryVM> GetListOfNodes() { List <Category> sourceCategories = db.Categories.ToList(); List <CategoryVM> categories = new List <CategoryVM>(); foreach (Category sourceCategory in sourceCategories) { CategoryVM c = new CategoryVM(); c.Id = sourceCategory.Id; c.CategoryName = sourceCategory.CategoryName; if (sourceCategory.ParentCategoryId != null) { c.Parent = new CategoryVM(); c.Parent.Id = (int)sourceCategory.ParentCategoryId; } categories.Add(c); } return(categories); }
public async Task <ActionResult> Create(CategoryVM model) { if (!ModelState.IsValid) { return(View(model)); } OperationResult result = await _categoryManager.CreateAsync(model.Name); if (result.Type == ResultType.Success) { //_toast.AddSuccessToastMessage("Category has been successfully created"); //return View(); return(RedirectToAction(nameof(List))); } ModelState.AddModelError(nameof(model.Name), result.BuildMessage()); return(View(model)); }
public IHttpActionResult Put(CategoryVM request) { if (request.Name.IsNullOrEmpty() && request.Id < 1) { return this.BadRequest("Category not valid."); } Category category = this.categoryService.FindCategory(request.Id); if (category == null) { return this.NotFound(); } category.Name = request.Name; if (this.categoryService.EditCategory(category)) { List<CategoryVM> categories = GetCategories(); return this.Ok(categories); } return this.BadRequest(); }
private void SubscribeHandlers(CategoryVM category) { category.EntityDeleted += (s, e) => _categories.Remove(SelectedCategory); }
private void AddCategory() { var category = new CategoryVM(_categoriesService); SubscribeHandlers(category); _categories.Add(category); }