public async Task <IActionResult> Edit(Guid id, [Bind("Id, Name")] CategoryInterestPointViewModel vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(NotFound()); } var result = getOperation.Result; if (!vm.CompareToModel(result)) { result.Name = vm.Name; var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception); return(View(vm)); } else { return(OperationSuccess("The record was successfuly updated")); } } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(NotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } ; if (getOperation.Result == null) { return(NotFound()); } var vm = CategoryInterestPointViewModel.Parse(getOperation.Result); ViewData["Title"] = "Category Interest Point"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "New", Controller = "CategoryInterestPoints", Icon = "fa-search", Text = "Detail" }); ViewData["BreadCrumbs"] = crumbs; return(View(vm)); }
public ActionResult Update([FromBody] CategoryInterestPointViewModel c) { var currentResult = _bo.Read(c.Id); if (!currentResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.Name == c.Name) { return(new ObjectResult(HttpStatusCode.NotModified)); } if (current.Name != c.Name) { current.Name = c.Name; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } return(Ok()); }
public async Task <IActionResult> Index() { var listOperation = await _bo.ListAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var ipListOperation = await _ipbo.ListAsync(); if (!ipListOperation.Success) { return(OperationErrorBackToIndex(ipListOperation.Exception)); } var cipListOperation = await _cipbo.ListAsync(); if (!cipListOperation.Success) { return(OperationErrorBackToIndex(cipListOperation.Exception)); } var list = new List <InterestPointCategoryInterestPointViewModel>(); foreach (var item in listOperation.Result) { if (!item.IsDeleted) { list.Add(InterestPointCategoryInterestPointViewModel.Parse(item)); } } var ipList = new List <InterestPointViewModel>(); foreach (var item in ipListOperation.Result) { if (!item.IsDeleted) { ipList.Add(InterestPointViewModel.Parse(item)); } } var cipList = new List <CategoryInterestPointViewModel>(); foreach (var item in cipListOperation.Result) { if (!item.IsDeleted) { cipList.Add(CategoryInterestPointViewModel.Parse(item)); } } ViewData["Title"] = "Interest Point Categories - Interest Points "; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); ViewBag.InterestPoints = ipList; ViewBag.CategoryInterestPoints = cipList; return(View(list)); }
public ActionResult Create([FromBody] CategoryInterestPointViewModel vm) { var c = new CategoryInterestPoint(vm.Name); var res = _bo.Create(c); var code = res.Success ? HttpStatusCode.OK : HttpStatusCode.InternalServerError; return(new ObjectResult(code)); }
public async Task <IActionResult> Create() { var ipListOperation = await _ipbo.ListAsync(); if (!ipListOperation.Success) { return(OperationErrorBackToIndex(ipListOperation.Exception)); } var ipList = new List <InterestPointViewModel>(); foreach (var ip in ipListOperation.Result) { if (!ip.IsDeleted) { var ipvm = InterestPointViewModel.Parse(ip); ipList.Add(ipvm); } ViewBag.InterestPoints = ipList.Select(icip => new SelectListItem() { Text = icip.Name, Value = icip.Id.ToString() }); } var cipListOperation = await _cipbo.ListAsync(); if (!cipListOperation.Success) { return(OperationErrorBackToIndex(cipListOperation.Exception)); } var cipList = new List <CategoryInterestPointViewModel>(); foreach (var cip in cipListOperation.Result) { if (!cip.IsDeleted) { var cipvm = CategoryInterestPointViewModel.Parse(cip); cipList.Add(cipvm); } ViewBag.CategoryInterestPoints = cipList.Select(icip => new SelectListItem() { Text = icip.Name, Value = icip.Id.ToString() }); } ViewData["Title"] = "New Interest Point Categories"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "New", Controller = "InterestPointsCategoryInterestPoints", Icon = "fa-plus", Text = "New" }); ViewData["BreadCrumbs"] = crumbs; return(View()); }
public ActionResult <List <CategoryInterestPointViewModel> > List() { var res = _bo.List(); if (!res.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } var list = new List <CategoryInterestPointViewModel>(); foreach (var item in res.Result) { list.Add(CategoryInterestPointViewModel.Parse(item)); } return(list); }
public async Task <IActionResult> Create([Bind("Name")] CategoryInterestPointViewModel vm) { if (ModelState.IsValid) { var categoryInterestPoint = vm.ToCategoryInterestPoint(); var createOperation = await _bo.CreateAsync(categoryInterestPoint); if (!createOperation.Success) { return(OperationErrorBackToIndex(createOperation.Exception)); } else { return(OperationSuccess("The record was successfuly created")); } } return(View(vm)); }
public ActionResult <CategoryInterestPointViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) { return(NotFound()); } var cvm = CategoryInterestPointViewModel.Parse(res.Result); return(cvm); } else { return(new ObjectResult(HttpStatusCode.InternalServerError)); } }