public async Task <IActionResult> Edit(int id, [Bind("ID,Name,CategoryID,SeoDescription,HtmlDescription,SeoKeywords")] CategorySub categorySub) { if (id != categorySub.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(categorySub); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategorySubExists(categorySub.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "ID", categorySub.CategoryID); return(View(categorySub)); }
public async Task <VerifyRecordResult> DeleteAsync(int id) { try { CleanTrackingHelper.Clean <CategorySub>(context); CategorySub item = await context.CategorySub .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == id); if (item == null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法刪除紀錄)); } else { CleanTrackingHelper.Clean <CategorySub>(context); context.Entry(item).State = EntityState.Deleted; await context.SaveChangesAsync(); CleanTrackingHelper.Clean <CategorySub>(context); return(VerifyRecordResultFactory.Build(true)); } } catch (Exception ex) { Logger.LogError(ex, "刪除記錄發生例外異常"); return(VerifyRecordResultFactory.Build(false, "刪除記錄發生例外異常", ex)); } }
public PartialViewResult EditCategorySub(int categorysubId, int categoryId) { var model = new CategorySub(); model = CategorySubBusiness.GetCategorySubByCategorySubIdAndCategoryId(categorysubId, categoryId); return(PartialView("EditCategorySub", model)); }
public PartialViewResult AddCategorySub(int categoryId) { var categorySub = new CategorySub(); categorySub.CategoryId = categoryId; return(PartialView("AddCategorySub", categorySub)); }
public async Task <IActionResult> PutCategorySub([FromRoute] int id, [FromBody] CategorySub categorySub) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != categorySub.ID) { return(BadRequest()); } _context.Entry(categorySub).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategorySubExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
async Task 建立派工單分類清單Async() { List <CategorySub> categorySubs = new List <CategorySub>(); int cc = 1; #region 派工單主分類 for (int i = 0; i < 20; i++) { int main = i; var categoryMain = new CategoryMain() { Name = $"派工單主分類{i}", Enable = true, }; await context.CategoryMain.AddAsync(categoryMain); await context.SaveChangesAsync(); categorySubs.Clear(); for (int j = 0; j < 20; j++) { CategorySub categorySub = new CategorySub() { CategoryMainId = categoryMain.Id, Code = $"{cc:#####}", Enable = true, Name = $"派工單次分類 {main}-{j}", OrderNumber = cc, }; categorySubs.Add(categorySub); } await context.BulkInsertAsync(categorySubs); } #endregion }
public async Task <VerifyRecordResult> UpdateAsync(CategorySubAdapterModel paraObject) { try { CategorySub itemData = Mapper.Map <CategorySub>(paraObject); CleanTrackingHelper.Clean <CategorySub>(context); CategorySub item = await context.CategorySub .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == paraObject.Id); if (item == null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法修改紀錄)); } else { CleanTrackingHelper.Clean <CategorySub>(context); context.Entry(itemData).State = EntityState.Modified; await context.SaveChangesAsync(); CleanTrackingHelper.Clean <CategorySub>(context); return(VerifyRecordResultFactory.Build(true)); } } catch (Exception ex) { Logger.LogError(ex, "修改記錄發生例外異常"); return(VerifyRecordResultFactory.Build(false, "修改記錄發生例外異常", ex)); } }
public ActionResult DeleteConfirmed(int id) { CategorySub categorySub = db.CategoriesSub.Find(id); db.CategoriesSub.Remove(categorySub); db.SaveChanges(); return(RedirectToAction("Index")); }
public void CreateCategorySub(FormCollection form) { CategorySub categorysub = JsonConvert.DeserializeObject <CategorySub>(form["CategorySubObj"]); categorysub.CategorySub_Status = true; categorysub.Category = db.Categories.Find(categorysub.Category_Id); db.CategoriesSub.Add(categorysub); db.SaveChanges(); }
public static CategorySubViewModel GetCategorySubByCategorySubIdAndCategoryId(int categorysubId, int categoryId) { CategorySub categorySub = identityASPdb.CategorySub.Where(x => x.isDelete != true && x.Id == categorysubId && x.CategoryId == categoryId).FirstOrDefault(); var model = new CategorySubViewModel(); model.Id = categorySub.Id; model.Description = categorySub.Description; model.CategoryId = categorySub.CategoryId; return(model); }
public ActionResult Edit([Bind(Include = "CategorySub_Id,Category_Id,CategorySub_Title,CategorySub_Code,CategorySub_Description,CategorySub_Status")] CategorySub categorySub) { if (ModelState.IsValid) { db.Entry(categorySub).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Category_Id = new SelectList(db.Categories, "Category_Id", "Category_Title", categorySub.Category_Id); return(View(categorySub)); }
public async Task <IActionResult> PostCategorySub([FromBody] CategorySub categorySub) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.CategorySubs.Add(categorySub); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCategorySub", new { id = categorySub.ID }, categorySub)); }
public async Task <IActionResult> Create([Bind("ID,Name,CategoryID,SeoDescription,HtmlDescription,SeoKeywords")] CategorySub categorySub) { if (ModelState.IsValid) { _context.Add(categorySub); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", categorySub.CategoryID); return(View(categorySub)); }
public async Task <CategorySubAdapterModel> GetAsync(int id) { CategorySub item = await context.CategorySub .AsNoTracking() .Include(x => x.CategoryMain) .FirstOrDefaultAsync(x => x.Id == id); CategorySubAdapterModel result = Mapper.Map <CategorySubAdapterModel>(item); await OhterDependencyData(result); return(result); }
// GET: CategoriesSub/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategorySub categorySub = db.CategoriesSub.Find(id); if (categorySub == null) { return(HttpNotFound()); } return(View(categorySub)); }
// Details public ActionResult SubCategoryDetails(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategorySub subCategory = db.CategorySub.Find(id); if (subCategory == null) { return(HttpNotFound()); } return(View(subCategory)); }
// GET: CategoriesSub/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategorySub categorySub = db.CategoriesSub.Find(id); if (categorySub == null) { return(HttpNotFound()); } ViewBag.Category_Id = new SelectList(db.Categories, "Category_Id", "Category_Title", categorySub.Category_Id); return(View(categorySub)); }
public void UpdateCategorySub(FormCollection form) { CategorySub categorysub = JsonConvert.DeserializeObject <CategorySub>(form["CategorySubObj"]); var id = categorysub.CategorySub_Id; var catsub_db = db.CategoriesSub.Find(id); catsub_db.Category_Id = categorysub.Category_Id; catsub_db.Category = db.Categories.Find(categorysub.Category_Id); catsub_db.CategorySub_Title = categorysub.CategorySub_Title; catsub_db.CategorySub_Code = categorysub.CategorySub_Code; catsub_db.CategorySub_Description = categorysub.CategorySub_Description; db.Entry(catsub_db).State = EntityState.Modified; db.SaveChanges(); }
// GET: Admin/CategoryDetails/Create public IActionResult Create(int?id) { ViewData["CategorySubID"] = new SelectList(_context.CategorySubs, "ID", "Name"); CategoryDetail detail = new CategoryDetail(); if (id != null) { CategorySub sub = _context.CategorySubs.Where(s => s.ID == id).Single(); if (sub != null) { detail.CategorySubID = sub.ID; ViewData["SenderID"] = sub.ID; } } return(View(detail)); }
public void SetTypeValue(Object sender, Object rowObject, Object newValue) { if (sender is OLVColumn) { int rowIndex = (int)rowObject; string columnName = ((OLVColumn)sender).Name; CategorySub sub = this.category.SubCategories[columnName]; if (sub != null) { if (sub.Types.Count > rowIndex) { string name = (string)newValue; if (DomainModel.Types.Update(sub, sub.Types[rowIndex], name)) { sub.Types[rowIndex].Name = name; } else { // Do nothing } } else { int typeId = -1; CategorySub neighbour = this.category.GetSubByTypesCount(rowIndex); if (neighbour != null) { typeId = neighbour.Types[rowIndex].Id; } GeneralType type = new GeneralType(); type.Name = (string)newValue; type.Id = typeId; if (DomainModel.Types.Insert(this.category, sub, type)) { sub.Types.Add(type); } } } } else { } }
// GET: Admin/CategorySubs/Create public IActionResult Create(int?id) { CategorySub sub = new CategorySub(); Category category = null; if (id != null) { category = _context.Categories.Single(c => c.ID == id); if (sub != null) { sub.CategoryID = category.ID; ViewData["SenderID"] = category.ID; } } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name"); return(View(sub)); }
private static void BuildCache() { classes = new CategoryClassCollection(); categoriesRepo.LoadAll(classes); foreach (Entities.CategoryClass cat in classes) { foreach (Culture culture in DomainModel.Cultures.GetAll()) { GeneralTypeCollection types = Types.GetByName(cat.Name, culture); CategorySub sub = new CategorySub(); sub.Language = culture; sub.Types = types; cat.SubCategories.Add(sub); } } }
public async Task <VerifyRecordResult> AddAsync(CategorySubAdapterModel paraObject) { try { CategorySub itemParameter = Mapper.Map <CategorySub>(paraObject); CleanTrackingHelper.Clean <CategorySub>(context); await context.CategorySub .AddAsync(itemParameter); await context.SaveChangesAsync(); CleanTrackingHelper.Clean <CategorySub>(context); return(VerifyRecordResultFactory.Build(true)); } catch (Exception ex) { Logger.LogError(ex, "新增記錄發生例外異常"); return(VerifyRecordResultFactory.Build(false, "新增記錄發生例外異常", ex)); } }
public Object GetTypeValue(Object sender, Object rowObject) { if (sender is OLVColumn) { int rowIndex = (int)rowObject; string columnName = ((OLVColumn)sender).Name; CategorySub sub = this.category.SubCategories[columnName]; if (sub != null && sub.Types.Count > rowIndex) { return(sub.Types[rowIndex].Name); } } else { } return(string.Empty); }
public async Task EnableIt(CategorySubAdapterModel paraObject) { CategorySub itemData = Mapper.Map <CategorySub>(paraObject); CleanTrackingHelper.Clean <CategorySub>(context); CategorySub item = await context.CategorySub .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == paraObject.Id); if (item == null) { } else { item.Enable = true; context.Entry(item).State = EntityState.Modified; await context.SaveChangesAsync(); CleanTrackingHelper.Clean <MenuData>(context); } }
public static bool DeleteCategorySub(int categorysubId) { try { if (categorysubId != 0) { CategorySub categorySub = identityASPdb.CategorySub.Where(x => x.Id == categorysubId).FirstOrDefault(); categorySub.isDelete = true; // set flag to true(deleted) identityASPdb.Entry(categorySub).State = EntityState.Modified; identityASPdb.SaveChanges(); result = true; } } catch (Exception) { throw; } return(result); }
// --------- Save Sub Category --------- ! public JsonResult SaveSubCategoryInDatabase(CategorySub model) { string Msg = null; CategorySub subCategory = new CategorySub(); var SubCategoryName = db.CategorySub.Where(c => c.SubCategoryName == model.SubCategoryName && c.CategoryID == model.CategoryID).FirstOrDefault(); if (ModelState.IsValid) { if (SubCategoryName == null) { if (model.SubCategoryID > 0) { subCategory = db.CategorySub.SingleOrDefault(x => x.SubCategoryID == model.SubCategoryID); subCategory.SubCategoryName = model.SubCategoryName; db.SaveChanges(); Msg = "Sub Category Update Successfully"; } else { subCategory.SubCategoryName = model.SubCategoryName; subCategory.MainCategoryID = model.MainCategoryID; subCategory.CategoryID = model.CategoryID; db.CategorySub.Add(subCategory); db.SaveChanges(); Msg = "Sub Category Save Successfully"; } } else { Msg = "Item Name already Exists"; } } return(Json(Msg, JsonRequestBehavior.AllowGet)); }
public static bool AddCategorySub(CategorySubViewModel model, out int categorysubId) { var categorysub = new CategorySub(); if (model.Id == 0) { try { categorysub.CategoryId = model.CategoryId; categorysub.Id = model.Id; categorysub.Description = model.Description; identityASPdb.CategorySub.Add(categorysub); identityASPdb.SaveChanges(); result = true; } catch (Exception) { throw; } } categorysubId = categorysub.Id; return(result); }
public static bool Insert(CategoryClass category, CategorySub sub, GeneralType type) { return(repo.Insert(category.Id, sub.Language.Id, type)); }
public static CategorySub GetCategorySubByCategorySubIdAndCategoryId(int categorysubId, int categoryId) { CategorySub categorySub = identityASPdb.CategorySub.Where(x => x.Id == categorysubId && x.CategoryId == categoryId && x.isDelete != true).FirstOrDefault(); return(categorySub); }