public async Task <VmGenericServiceResult> Update(VmBlogItem vmBlogItem) { VmGenericServiceResult result = new VmGenericServiceResult(); try { Blog r = await repo.Get(vmBlogItem.Id); Copy <VmBlogItem, Blog>(vmBlogItem, 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 VmGenericServiceResult Insert(VmBlogItem vmBlogItem) { VmGenericServiceResult result = new VmGenericServiceResult(); try { Blog r = new Blog(); Copy <VmBlogItem, Blog>(vmBlogItem, r); if (r.CreatedBy.IsNullOrEmpty()) { r.CreatedBy = r.UpdatedBy = "System"; } repo.Add(r); repo.Commit(); result.IsSuccess = true; } catch (Exception e) { result.IsSuccess = false; result.Error = e; } return(result); }
public async Task <VmBlogPage> GetBlogsByPage(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 VmBlogPage()); } var resultObj = new VmBlogPage(); //resultObj.ApplicationToken = applicationToken; resultObj.RequestId = DateTime.Now.ToString("yyyyMMddHHmmss"); resultObj.RequestDate = DateTime.Now; resultObj.Result = new PageResult <VmBlogItem>(); resultObj.Result.Records = new List <VmBlogItem>(); Copy <PageResult <Blog>, PageResult <VmBlogItem> >(dbPageResult, resultObj.Result, new string[] { "Records" }); foreach (var dbItem in dbPageResult.Records) { var resultItem = new VmBlogItem(); Copy <Blog, VmBlogItem>(dbItem, resultItem); resultObj.Result.Records.Add(resultItem); } return(resultObj); }
// GET: Blogs/Details/5 public async Task <IActionResult> Details(int id) { VmBlogItem item = await svs.GetBlogById(id); if (item == null) { return(NotFound()); } return(View(item)); }
//public async Task<IActionResult> Create([Bind("Id, Blog, BlogCode")] VmBlogItem Blogs) public async Task <IActionResult> Create(VmBlogItem Blogs) { var result = svs.Insert(Blogs); if (result.IsSuccess) { return(RedirectToAction(nameof(Index))); } else { return(View(Blogs)); } }
public async Task <VmBlogItem> GetBlogById(int Id) { var dbPageResult = await repo.Get(Id); if (dbPageResult == null) { return(new VmBlogItem()); } var resultObj = new VmBlogItem(); Copy <Blog, VmBlogItem>(dbPageResult, resultObj); return(resultObj); }
// GET: Blogs/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } int _id = (int)id; VmBlogItem rItem = await svs.GetBlogById(_id); if (rItem == null) { return(NotFound()); } return(View(rItem)); }
//public async Task<IActionResult> Edit(int id, [Bind("Id, Blog, BlogCode, UpdatedBy, CreatedDate, CreatedBy, Version, IsActive")] Blogs Blogs) //public async Task<IActionResult> Edit(int id, [Bind("Id, Blog, BlogCode, UpdatedBy, Version, IsActive")] VmBlogItem Blogs) public async Task <IActionResult> Edit(int id, VmBlogItem Blogs) { if (id != Blogs.Id) { return(NotFound()); } var result = await svs.Update(Blogs); if (result.IsSuccess) { return(RedirectToAction(nameof(Index))); } else { return(View(Blogs)); } }
// GET: Blogs/Create public ActionResult Create() { VmBlogItem BlogObj = new VmBlogItem(); return(View(BlogObj)); }