void SelectCategory(ChangeEventArgs e, AdsCategoryViewModel category) { bool isChecked = (bool)e.Value; if (isChecked) { if (string.IsNullOrEmpty(_options.Category)) { _options.Category = category.CategoryId.ToString(); } else { var items = new List <string>(_options.Category.Split(';')) { category.CategoryId.ToString() }; _options.Category = string.Join(';', items); } } else if (!string.IsNullOrEmpty(_options.Category)) { var list = new List <string>(_options.Category.Split(';')); list.Remove(category.CategoryId.ToString()); _options.Category = string.Join(';', list); } }
public ActionResult Add_Ads() { var categories = _context.Category_db.ToList(); var viewmodel = new AdsCategoryViewModel { Category = categories }; return(View(viewmodel)); }
private async Task <AdsCategoryViewModel> ImportCategory(ExchangeDataRow item, AdsImportResultViewModel importResult) { if (!Guid.TryParse(item.FamilyId, out var familyId)) { _logger.LogWarning($"ParentId:{item.FamilyId} is not a guid"); } if (!Guid.TryParse(item.CategoryId, out var categoryId)) { _logger.LogWarning($"CategoryId:{item.CategoryId} is not a guid"); } var family = await ImportFamily(item, importResult); var current = await _adsUnitOfWork. CategoriesRepository.Get(categoryId); if (current == null) { _logger.LogInformation($"Create new category with id {categoryId} code {item.Code} label {item.Label}"); current = new AdsCategoryViewModel() { CategoryId = categoryId, Code = item.Code, Label = item.Label, FamilyId = family.FamilyId, MetaDescription = item.MetaDescription, MetaKeywords = item.MetaKeywords, MetaTitle = item.MetaTitle, PictureUrl = item.PictureUrl }; importResult.CategoriesAdded += 1; await _adsUnitOfWork.CategoriesRepository.Add(current); } else if (item.Type.Equals("category", StringComparison.OrdinalIgnoreCase)) { _logger.LogInformation($"Update Category with id {categoryId} code {current.Code} label {current.Label}"); current.CategoryId = categoryId; current.Code = item.Code; current.Label = item.Label; current.FamilyId = familyId; current.MetaDescription = item.MetaDescription; current.MetaKeywords = item.MetaKeywords; current.MetaTitle = item.MetaTitle; current.PictureUrl = item.PictureUrl; importResult.CategoriesUpdated += 1; await _adsUnitOfWork.CategoriesRepository.Update(current); } return(current); }
public async Task <ActionResult <AdsCategoryViewModel> > Create(AdsCategoryViewModel categoryView) { if (!ModelState.IsValid) { return(BadRequest()); } var inserted = await _adsUnitOfWork.CategoriesRepository.Add(categoryView); return(Created($"{inserted.CategoryId}", inserted)); }
public ActionResult UpdateAd(int IdOfProduct) { var categories = _context.Category_db.ToList(); var result = _context.Ads_db.Where(m => m.ADs_ID == IdOfProduct).First(); var viewmodel = new AdsCategoryViewModel { Category = categories, Ad = result }; return(View(viewmodel)); }
public ActionResult UpdateAdDB(AdsCategoryViewModel Ad1, HttpPostedFileBase imgFile) { if (imgFile != null) { string path1 = Path.Combine(Server.MapPath("~/Uploads"), imgFile.FileName); imgFile.SaveAs(path1); Ad1.Ad.Ad_image = imgFile.FileName; _context.Entry(Ad1.Ad).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("ViewOneAdForUser", "Account", new { IdOfProduct = Ad1.Ad.ADs_ID })); } return(RedirectToAction("ViewOneAdForUser", "Account", new { IdOfProduct = Ad1.Ad.ADs_ID })); }
private void ParseCategory(AdsCategoryViewModel category, IList <ExchangeDataRow> models) { models.Add(new ExchangeDataRow { Type = "Category", FamilyId = category.FamilyId.ToString(), CategoryId = category.CategoryId.ToString(), Code = category.Code, Label = category.Label, MetaTitle = category.MetaTitle, MetaDescription = category.MetaDescription, MetaKeywords = category.MetaKeywords }); }
bool IsCategorySelected(AdsCategoryViewModel category) { if (_options == null) { return(false); } if (string.IsNullOrEmpty(_options.Category)) { return(false); } var list = new List <string>(_options.Category.Split(';')); return(list.Contains(category.CategoryId.ToString())); }
public async Task <ActionResult <AdsCategoryViewModel> > Update(Guid id, AdsCategoryViewModel categoryView) { if (categoryView == null) { return(BadRequest()); } if (categoryView.CategoryId != id) { return(BadRequest()); } var entity = await _adsUnitOfWork.CategoriesRepository.Update(categoryView); return(Ok(categoryView)); }
public ActionResult AddadsDB(AdsCategoryViewModel Ad1, HttpPostedFileBase imgFile) { string x = Session["username"].ToString(); var result = _context.User_db.Where(m => m.User_Name == x).First(); Ad1.Ad.User_id = result.User_ID; if (imgFile != null) { string path1 = Path.Combine(Server.MapPath("~/Uploads"), imgFile.FileName); imgFile.SaveAs(path1); Ad1.Ad.Ad_image = imgFile.FileName; _context.Ads_db.Add(Ad1.Ad); _context.SaveChanges(); var resultofcateg = _context.Category_db.Where(m => m.Categories_ID == Ad1.Ad.Ads_Categories).First(); resultofcateg.number_of_products++; _context.Entry(resultofcateg).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("ViewAllAds", "Ads")); } return(View()); }
private async Task SelectCategory(AdsCategoryViewModel category) { category.Selected = !category.Selected; await RefeshResultFilter(); }