public ActionResult EditBusinessCategory(BusinessCategory bs) { if (bs != null && bs.Id != Guid.Empty) { bs.BusinessCategoryParent = null; businessCategoryService.Update(bs); return Json(true, JsonRequestBehavior.AllowGet); } return Json(false, JsonRequestBehavior.AllowGet); }
public ActionResult AddBusinessCategory(BusinessCategory bs) { if (bs != null) { bs.Id = Guid.NewGuid(); businessCategoryService.Add(bs); return Json(true, JsonRequestBehavior.AllowGet); } return Json(false, JsonRequestBehavior.AllowGet); }
private void SaveChildParent(BusinessCategory item, List<BusinessCategory> listCategory) { if (item.CategoryId < item.CategoryParentId || item.CategoryParentId > 0) { var p = businessCategoryService.Get().Where(c => c.CategoryId == item.CategoryParentId).FirstOrDefault(); if (p == null) { p = (from a in listCategory where a.CategoryId == item.CategoryParentId select a).FirstOrDefault(); if (p != null) { SaveChildParent(p, listCategory); } } } var child = businessCategoryService.GetByFactualCategoryId(item.CategoryId); if (child == null) businessCategoryService.Add(item); }
public ActionResult ImportCategory(int? categoryId) { rootId = categoryId ?? 0; string pathFile = String.Format(@"{0}\{1}", Server.MapPath("/"), @"Upload\fractualcategory.txt"); //read file string category = System.IO.File.ReadAllText(pathFile); var json_serializer = new JavaScriptSerializer(); var routes_list = (IDictionary<string, object>)json_serializer.DeserializeObject(category); List<BusinessCategory> listCategory = new List<BusinessCategory>(); Dictionary<string, Guid> listReference = new Dictionary<string, Guid>(); foreach (var item in routes_list) { if (item.Key != "1") { #region Import BusinessCategory cate = new BusinessCategory(); cate.Id = Guid.NewGuid(); cate.CategoryId = Int32.Parse(item.Key); var valueCate = item.Value as Dictionary<string, object>; var labels = valueCate["labels"] as Dictionary<string, object>; var parents = valueCate["parents"]; var isabstract = valueCate["abstract"]; listReference.Add(item.Key, cate.Id); //convert parents if (parents != null) { var arrParents = parents as object[]; if (arrParents != null && arrParents.Count() > 0) { cate.CategoryParentId = Int32.Parse(arrParents[0].ToString()); } } //convert isabstract cate.IsAbstract = Boolean.Parse(isabstract.ToString()); //convert label if (labels != null) { var arrLabel = labels;//labels.Value as KeyValuePair<string, object>[]; if (arrLabel != null && arrLabel.Count() > 0) { foreach (var l in arrLabel) { switch (l.Key.ToString()) { case "kr": cate.KR = l.Value.ToString(); break; case "zh_hant": cate.ZH_HANT = l.Value.ToString(); break; case "en": cate.EN = l.Value.ToString(); cate.Name = l.Value.ToString(); break; case "zh": cate.ZH = l.Value.ToString(); break; case "jp": cate.JP = l.Value.ToString(); break; case "pt": cate.PT = l.Value.ToString(); break; case "de": cate.DE = l.Value.ToString(); break; case "it": cate.IT = l.Value.ToString(); break; case "es": cate.ES = l.Value.ToString(); break; case "fr": cate.FR = l.Value.ToString(); break; } } } } if (cate.CategoryId == categoryId || GetRootParent(cate.CategoryId, routes_list)) { if (cate.CategoryId == categoryId) cate.CategoryParentId = null; listCategory.Add(cate); } #endregion } } AddParentToList(listReference, listCategory); //save to db foreach (var item in listCategory) { SaveChildParent(item, listCategory); } return Json(true, JsonRequestBehavior.AllowGet); }
public ActionResult GetInfo(FactualDownloadParameter parameter) { List<BusinessCategoryViewModel> listReturn = new List<BusinessCategoryViewModel>(); if (parameter != null) { //get zip code of county var zipcodes = zipcodeService.Get() .Where(c => c.City.Equals(parameter.City) && c.Country.Equals(parameter.Country) && c.State.Equals(parameter.State)) .ToList(); //get categoryL1 BusinessCategory CategoryL1; BusinessCategory CategoryL2; BusinessCategory CategoryL3; BusinessCategory CategoryL4; BusinessCategory MainCategory = new BusinessCategory(); ArrayList category_ids = new ArrayList(); if (parameter.CategoryL1 != null) { CategoryL1 = businessCategoryService.Get(parameter.CategoryL1); MainCategory = CategoryL1; if (MainCategory != null) { category_ids.Add(MainCategory.CategoryId); } } if (parameter.CategoryL2 != null && parameter.CategoryL2 != Guid.Empty) { CategoryL2 = businessCategoryService.Get(parameter.CategoryL2); MainCategory = CategoryL2; if (MainCategory != null) { category_ids.Add(MainCategory.CategoryId); } } if (parameter.CategoryL3 != null && parameter.CategoryL3 != Guid.Empty) { CategoryL3 = businessCategoryService.Get(parameter.CategoryL3); MainCategory = CategoryL3; if (MainCategory != null) { category_ids.Add(MainCategory.CategoryId); } } if (parameter.CategoryL4 != null && parameter.CategoryL4 != Guid.Empty) { CategoryL4 = businessCategoryService.Get(parameter.CategoryL4); MainCategory = CategoryL4; if (MainCategory != null) { category_ids.Add(MainCategory.CategoryId); } } string categoryIDs = string.Join(",", category_ids.ToArray()); if (MainCategory != null && MainCategory.Id != Guid.Empty) { foreach (var zip in zipcodes) { //insert new Category_ZipCode cate = new Category_ZipCode(); cate.Id = Guid.NewGuid(); cate.BusinessCategoryId = MainCategory.Id; cate.ZipcodeId = zip.Id; cate.ZipcodeName = zip.Zip; cate.TotalRecord = 0; cate.Downloaded = 0; cate.CategoryName = MainCategory.Name; cate.CategoryId = MainCategory.CategoryId; var cate_zip = category_ZipCodeService.Get().FirstOrDefault(c => c.BusinessCategoryId == MainCategory.Id && c.ZipcodeName == zip.Zip); if (cate_zip == null) { category_ZipCodeService.Add(cate); } //convert to businesCategory View model BusinessCategoryViewModel model = new BusinessCategoryViewModel(); model.Category_ZipId = cate.Id; model.Zipcode = zip.Zip; model.TotalDownloaded = cate_zip == null ? 0 : cate_zip.Downloaded; model.State = zip.State; model.City = zip.City; model.Availble = cate_zip == null ? 0 : cate_zip.TotalRecord; model.IsChoose = false; model.CategoryInclude = categoryIDs; listReturn.Add(model); } } } return Json(listReturn, JsonRequestBehavior.AllowGet); }