public AddNewRecipeVM(CategoriesDTO catRow, DirectionsDTO dirRow, DishesDTO disRow, IngredientsDTO ingRow) { Categories = new CategoriesVM(catRow); Directions = new DirectionsVM(dirRow); Dishes = new DishesVM(disRow); Ingredients = new IngredientsVM(ingRow); }
public CategoryVM(CategoriesDTO row) { Id = row.Id; Name = row.Name; Slug = row.Slug; Sorting = row.Sorting; }
public string AddNewCategory(string catName, string catDesc) { string id; // string catName = cat[0]; //tring catDesc = cat[1]; using (DB db = new DB()) { if (db.Categories.Any(x => x.Name == catName)) { return("titletaken"); } CategoriesDTO dto = new CategoriesDTO(); dto.Name = catName; dto.Slug = catName.Replace(" ", "-"); dto.Description = catDesc; dto.Sorting = 100; db.Categories.Add(dto); db.SaveChanges(); id = dto.Id.ToString(); } return(id); }
public ActionResult AddNew() { List <Level> level = new List <Level> { new Level() { Level_Id = 1, Level_Name = "Łatwy" }, new Level() { Level_Id = 2, Level_Name = "Średni" }, new Level() { Level_Id = 3, Level_Name = "Trudny" } }; CategoriesDTO catDTO = new CategoriesDTO(); DirectionsDTO dirDTO = new DirectionsDTO(); DishesDTO disDTO = new DishesDTO(); IngredientsDTO ingDTO = new IngredientsDTO(); AddNewRecipeVM model = new AddNewRecipeVM(catDTO, dirDTO, disDTO, ingDTO); using (Db db = new Db()) { model.Dishes.CategoriesSelectList = new SelectList(db.Categories.ToList(), "Id_Category", "Name"); model.LevelList = new SelectList(level, "Level_Id", "Level_Name"); } return(View(model)); }
public IActionResult Insert(string id, string CategoryName, string CategoryPath, int TopCategory, string Title, string Description, string SEOTitle, string SEODescription) { if (id == "0" || id == null) { var category = new CategoriesDTO() { CategoryName = CategoryName, Path = CategoryPath, ImagePath = "", MainCategoryId = TopCategory, Description = Description, Title = Title, SEODescription = SEODescription, SEOTitle = SEOTitle }; _categoryService.AddCategory(category); } else { _categoryService.UploadCategory(new CategoriesDTO() { Id = int.Parse(id), CategoryName = CategoryName, ImagePath = "", MainCategoryId = TopCategory, Path = CategoryPath, Description = Description, Title = Title, SEODescription = SEODescription, SEOTitle = SEOTitle }); } return(RedirectToAction("List")); }
public async Task <IActionResult> PutCategories(int id, CategoriesDTO categoriesDTO) { if (id != categoriesDTO.Id) { return(BadRequest()); } var categories = await _context.Categories.FindAsync(id); if (categories == null) { return(NotFound()); } categories.Name = categoriesDTO.Name; categories.Description = categoriesDTO.Description; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoriesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public CategoriesVM(CategoriesDTO catDto) { CatgId = catDto.CatgId; CategoryName = catDto.CategoryName; Slug = catDto.Slug; Sorting = catDto.Sorting; }
//catName dolazi iz Ajax public string AddNewCategory(string catName) { //Deklarisati id string id; using (ShoppingCartDB db = new ShoppingCartDB()) { //proveriti da li je category ime jedinstveno if (db.Categories.Any(x => x.Name == catName)) { return("titletaken"); } //inicijalizovati DTO CategoriesDTO dto = new CategoriesDTO(); //Dodati u DTO dto.Name = catName; dto.Slug = catName.Replace(" ", "-").ToLower(); //ista logika kao i za pageove kada se doda kategorija bice poslednja dto.Sorting = 100; //sacuvati DTO db.Categories.Add(dto); db.SaveChanges(); //uzeti ubaceni id id = dto.Id.ToString(); } //vratiti taj id return(id); }
public ActionResult EditCategory(CategoryVM categoryVM) { TextInfo text = CultureInfo.CurrentCulture.TextInfo; int id = categoryVM.Id; if (!ModelState.IsValid) { return(View(categoryVM)); } using (BankDB bankDB = new BankDB()) { CategoriesDTO categoriesDTO = bankDB.Categories.Find(id); if (bankDB.Categories.Where(x => x.Id != categoryVM.Id).Any(x => x.Name == categoryVM.Name)) { ModelState.AddModelError("nameExist", "Категория уже создана"); return(View(categoryVM)); } categoriesDTO.Name = text.ToTitleCase(categoryVM.Name); bankDB.SaveChanges(); } TempData["OK"] = "Категория изменена"; return(RedirectToAction("PageCategories")); }
public ActionResult CreateCategory(CategoryVM categoryVM) { TextInfo text = CultureInfo.CurrentCulture.TextInfo; if (!ModelState.IsValid) { return(View(categoryVM)); } using (BankDB bankDB = new BankDB()) { if (bankDB.Categories.Any(x => x.Name == categoryVM.Name)) { ModelState.AddModelError("catNameExist", "Эта категория уже создана"); return(View(categoryVM)); } CategoriesDTO categoriesDTO = new CategoriesDTO(); categoriesDTO.Name = text.ToTitleCase(categoryVM.Name); bankDB.Categories.Add(categoriesDTO); bankDB.SaveChanges(); } TempData["OK"] = "Категория создана"; return(View(categoryVM)); }
//using DTOs and AutoMapper public static void Query3() { InitializeMapperQ3(); using (var db = new ProductShopContext()) { var xmlDoc = new XDocument(); var categories = new CategoriesDTO() { Categories = db.Categories .ProjectTo <CategoryDTO>() .OrderByDescending(c => c.ProductsCount) .ToList() }; var serializer = new XmlSerializer(typeof(CategoriesDTO)); var writer = new StreamWriter("../../Export/categories-by-products.xml"); using (writer) { serializer.Serialize(writer, categories); } } }
public ActionResult GetCategories(int id) { try { CategoriesDTO Catgr = new CategoriesDTO(); using (MABRUKLISTEntities dbcontext = new MABRUKLISTEntities()) { var cat = dbcontext.mblist_service_category.Find(id); if (cat != null) { Catgr.id = cat.Category_key; Catgr.Category = cat.Category_Name; return(PartialView("_AddCategories", Catgr)); } else { return(Json(new { key = false, value = "Category not Found its Deleted from data base!!" }, JsonRequestBehavior.AllowGet)); } } } catch (Exception) { return(Json(new { key = false, value = "Unable to edit the Category" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult CreateCategory(CategoryVM cat) { if (!ModelState.IsValid) { return(View(cat)); } CategoriesDTO dto = new CategoriesDTO(); dto.Name = cat.Name; dto.Description = cat.Description; if (db.Categories.Any(x => x.Name == dto.Name)) { ModelState.AddModelError("", "The category already exists!"); return(View(cat)); } //insert and commit db.Categories.Add(dto); db.SaveChanges(); TempData["Status"] = "Category created! <3"; return(RedirectToAction("CreateCategory")); }
private void Addbutton_Click(object sender, EventArgs e) { var data = new CategoriesDTO(); //create map using automapper Mapper.CreateMap <CategoriesDTO, Category>(); try { data.Title = Titlebox.Text; data.Description = descriptionbox.Text; data.DateAdded = DateTime.Now; data.Addedby = userID; if ( String.IsNullOrWhiteSpace(data.Title) || String.IsNullOrWhiteSpace(data.Description) ) { MessageBox.Show("Input cannot be empty or whitespace"); return; } } catch (Exception exception) { //add error logger MessageBox.Show("One or more errors occured please try again"); return; } using (var db = new Model1()) { var category = Mapper.Map <CategoriesDTO, Category>(data); var val = db.Categories.FirstOrDefault(c => c.Title.ToLower() == category.Title.ToLower()); if (val != null) { MessageBox.Show("Category already exist"); return; } db.Categories.Add(category); var sol = db.SaveChanges() > 0; if (sol) { MessageBox.Show("Input saved successfully"); Titlebox.Clear(); descriptionbox.Clear(); //refreshing the datatable string searcher = ""; var found = from x in db.Categories where x.Title.Contains(searcher) || x.Description.Contains(searcher) select x; categorydataGridView.DataSource = found.ToList().ToDataTable(); } } }
public ActionResult CreatePage(PageVM pageVM) { if (!ModelState.IsValid) { using (BankDB bankDB = new BankDB()) { pageVM.categoryList = new SelectList(bankDB.Categories.ToList(), "Id", "Name"); return(View(pageVM)); } } using (BankDB bankDB = new BankDB()) { string description = null; PagesDTO pagesDTO = new PagesDTO(); pagesDTO.Title = pageVM.Title; if (string.IsNullOrWhiteSpace(pageVM.Description)) { description = pageVM.Title.Replace(" ", "-").ToLower(); } else { description = pageVM.Description.Replace(" ", "-").ToLower(); } if (bankDB.Pages.Any(x => x.Title == pageVM.Title)) { ModelState.AddModelError("titleExist", "Это имя страницы занято"); return(View(pageVM)); } else if (bankDB.Pages.Any(x => x.Description == pageVM.Description)) { ModelState.AddModelError("descrExist", "Этот адрес страницы занят"); return(View(pageVM)); } pagesDTO.Description = description; pagesDTO.Body = pageVM.Body; pagesDTO.SideBar = pageVM.Sidebar; pagesDTO.PageCategoryId = pageVM.PageCategoryId; CategoriesDTO categories = bankDB.Categories.FirstOrDefault(x => x.Id == pageVM.PageCategoryId); pagesDTO.PageCategory = categories.Name; bankDB.Pages.Add(pagesDTO); bankDB.SaveChanges(); } TempData["OK"] = "Страница создана"; return(RedirectToAction("Index")); }
/// <summary> ///get all the categories avaiable /// </summary> /// <returns></returns> public CategoriesDTO GetCategory() { IEnumerable <Category> categoryList = dbContext.Categories.ToList(); CategoriesDTO newCategoryDTO = new CategoriesDTO(); newCategoryDTO.Category = categoryListMapper.Map <IEnumerable <Category>, IEnumerable <CategoryDTO> >(categoryList); return(newCategoryDTO); }
private CategoriesDTO GetCategoriesFromDataRow(DataRow row) { CategoriesDTO dto = new CategoriesDTO(); dto.cateId = int.Parse(row["Id"].ToString()); dto.cateName = row["name"].ToString(); return(dto); }
public Categories ProductsByCategory(int id) { Categories ListaCategories = new CategoriesDTO().GetDTO(id); ListaCategories._Productos = new ProductsDTO().ProductosPorCategoria(ListaCategories.CategoryId); return(ListaCategories); }
public CategoriesVM(CategoriesDTO row) { Id = row.Id; Name = row.Name; Slug = row.Slug; Description = row.Description; Sorting = row.Sorting; }
public PartialViewResult GetCategories() { CategoriesViewModel categoriesViewModel = new CategoriesViewModel(); CategoriesDTO categoryDTOs = categoryBusinessContext.GetCategories(); categoriesViewModel.categories = categoryDTOs.categories; return(PartialView(categoriesViewModel)); }
public async Task Add(CategoriesDTO entity) { var category = new Categories(); category.Definition = entity.Definition; category.Id = ObjectId.GenerateNewId(); await _categoriesDal.AddAsync(category); }
public async Task UpdateAsync(CategoriesDTO entity) { var contract = new Categories { Id = new ObjectId((string)entity.Id), Definition = entity.Definition }; await _categoriesDal.UpdateAsync(x => x.Id == new ObjectId((string)entity.Id), contract); }
public ActionResult DeleteCategory(int id) { CategoriesDTO dto = db.Categories.Find(id); db.Categories.Remove(dto); db.SaveChanges(); return(RedirectToAction("Index")); }
public CategoriesDTO GetCategory() { CategoriesDTO categoriesDTO = new CategoriesDTO(); IEnumerable <string> categories = shoppingCartEntities.Categories.ToList().Select(p => p.Name); Debug.WriteLine(shoppingCartEntities.Categories.ToList().Select(p => p.Name)); categoriesDTO.categories = categories; return(categoriesDTO); }
private void updatebutton_Click(object sender, EventArgs e) { var data = new CategoriesDTO(); //create map using automapper Mapper.CreateMap <CategoriesDTO, Category>(); try { data.Title = Titlebox.Text; data.Description = descriptionbox.Text; data.DateAdded = DateTime.Now; data.Addedby = userID; if ( String.IsNullOrWhiteSpace(data.Title) || String.IsNullOrWhiteSpace(data.Description) ) { MessageBox.Show("Input cannot be empty or whitespace"); return; } } catch (Exception exception) { //add error logger MessageBox.Show("One or more errors occured please try again"); return; } using (var db = new Model1()) { var category = Mapper.Map <CategoriesDTO, Category>(data); var id = categoryidbox.Text; if (string.IsNullOrWhiteSpace(id)) { MessageBox.Show("ID cannot be empty"); return; } category.id = int.Parse(id); db.Categories.AddOrUpdate(category); var sol = db.SaveChanges() > 0; if (sol) { MessageBox.Show("Input Updated successfully"); Titlebox.Clear(); descriptionbox.Clear(); categoryidbox.Clear(); //code to refresh the data table var found = db.Categories.ToList(); categorydataGridView.DataSource = found.ToDataTable(); } } }
public bool AddCategory(CategoriesDTO categories) { return(_categoryRepository.Add(new Categories() { CategoryName = categories.CategoryName, MainCategoryId = categories.MainCategoryId, Path = categories.Path, ImagePath = categories.ImagePath })); }
public List <Categories> ProductsByCategory() { List <Categories> ListaCategories = new CategoriesDTO().GetDTO(); foreach (Categories ct in ListaCategories) { ct._Productos = new ProductsDTO().ProductosPorCategoria(ct.CategoryId); } return(ListaCategories); }
public int Create(CategoriesDTO request) { return(Execute( connection => connection.Query <int>("[dbo].[CreateNewCategory]", new { CategoryName = request.Name }, commandType: CommandType.StoredProcedure) ).First()); }
/// <summary> /// Get all categories /// </summary> /// <returns></returns> public static CategoriesDTO AllCategories() { try { CategoriesDTO categories = CategoryData.AllCategories(); return(categories); } catch (Exception) { return(null); } }
// GET: Admin/Shop/DeleteCategory/id public ActionResult DeleteCategory(int id) { using (Db db = new Db()) { CategoriesDTO dto = db.Categories.Find(id); db.Categories.Remove(dto); db.SaveChanges(); } return(RedirectToAction("Categories")); }