public async Task <VmCodeCategoryPage> GetCodeCategoryByPage(string keyword, int page, int totalRecords) { var dbPageResult = await repo.GetPage(keyword, (page == 0 ? Constants.app_firstPage : page), (totalRecords == 0 ? Constants.app_totalRecords : totalRecords)); if (dbPageResult == null) { return(new VmCodeCategoryPage()); } var resultObj = new VmCodeCategoryPage(); resultObj.RequestId = DateTime.Now.ToString("yyyyMMddHHmmss"); resultObj.RequestDate = DateTime.Now; resultObj.Result = new PageResult <VmCodeCategoryItem>(); resultObj.Result.Records = new List <VmCodeCategoryItem>(); Copy <PageResult <CodeCategory>, PageResult <VmCodeCategoryItem> >(dbPageResult, resultObj.Result, new string[] { "Records" }); foreach (var dbItem in dbPageResult.Records) { var resultItem = new VmCodeCategoryItem(); Copy <CodeCategory, VmCodeCategoryItem>(dbItem, resultItem); resultObj.Result.Records.Add(resultItem); } return(resultObj); }
public async Task <VmCodeTableItem> GetObject(int id) { VmCodeTableItem result = new VmCodeTableItem(); var dbCatList = await repoCate.GetAll(); if (dbCatList == null) { return(result); } result.CodeCategoryList = new List <VmCodeCategoryItem>(); foreach (var dbcat in dbCatList) { VmCodeCategoryItem cat = new VmCodeCategoryItem() { Id = dbcat.Id, Name = dbcat.Name }; result.CodeCategoryList.Add(cat); } return(result); }
public async Task <VmGenericServiceResult> Update(VmCodeCategoryItem vmCodeCategoryItem) { VmGenericServiceResult result = new VmGenericServiceResult(); try { CodeCategory r = await repo.Get(vmCodeCategoryItem.Id); Copy <VmCodeCategoryItem, CodeCategory>(vmCodeCategoryItem, r); if (r.UpdatedBy.IsNullOrEmpty()) { r.UpdatedBy = "System"; } repo.Update(r); repo.Commit(); result.IsSuccess = true; } catch (Exception e) { result.IsSuccess = false; result.Error = e; } return(result); }
public async Task <IActionResult> Create(VmCodeCategoryItem codeCategoryItem) { var result = svs.Insert(codeCategoryItem); if (result.IsSuccess) { return(RedirectToAction(nameof(Index))); } else { ViewData["Error"] = result.Error.Message; return(View(codeCategoryItem)); } }
public async Task <VmCodeCategoryItem> GetCodeCategoryById(int Id) { var dbPageResult = await repo.Get(Id); if (dbPageResult == null) { return(new VmCodeCategoryItem()); } var resultObj = new VmCodeCategoryItem(); Copy <CodeCategory, VmCodeCategoryItem>(dbPageResult, resultObj); return(resultObj); }
// GET: CodeCategory/Edit/5 public async Task <ActionResult> Edit(int id) { if (id == null) { return(NotFound()); } int _id = (int)id; VmCodeCategoryItem rItem = await svs.GetCodeCategoryById(_id); if (rItem == null) { return(NotFound()); } return(View(rItem)); }
public async Task <IActionResult> Edit(int id, VmCodeCategoryItem codeCategoriesItem) { if (id != codeCategoriesItem.Id) { return(NotFound()); } var result = await svs.Update(codeCategoriesItem); if (result.IsSuccess) { return(RedirectToAction(nameof(Index))); } else { return(View(codeCategoriesItem)); } }
public VmGenericServiceResult Insert(VmCodeCategoryItem vmCodeCategoryItem) { VmGenericServiceResult result = new VmGenericServiceResult(); try { CodeCategory r = new CodeCategory(); Copy <VmCodeCategoryItem, CodeCategory>(vmCodeCategoryItem, r); if (r.CreatedBy.IsNullOrEmpty()) { r.CreatedBy = r.UpdatedBy = "System"; } repo.Add(r); repo.Commit(); result.IsSuccess = true; } catch (Exception e) { result.IsSuccess = false; var repoEntity = repo.Get(vmCodeCategoryItem.Id); if (repoEntity != null) { Exception ee = new Exception("Id is already existed!"); result.Error = ee; } else { result.Error = e; } } return(result); }
public async Task <VmCodeTableItem> GetCodeTableById(int Id) { var dbPageResult = await repo.Get(Id); if (dbPageResult == null) { return(new VmCodeTableItem()); } var resultObj = new VmCodeTableItem(); Copy <CodeTable, VmCodeTableItem>(dbPageResult, resultObj); var dbCatList = await repoCate.GetAll(); if (dbCatList == null) { return(resultObj); } resultObj.CodeCategoryList = new List <VmCodeCategoryItem>(); foreach (var dbcat in dbCatList) { VmCodeCategoryItem cat = new VmCodeCategoryItem() { Id = dbcat.Id, Name = dbcat.Name }; resultObj.CodeCategoryList.Add(cat); } // return(resultObj); }
// GET: CodeCategory/Create public ActionResult Create() { VmCodeCategoryItem roleObj = new VmCodeCategoryItem(); return(View(roleObj)); }