public async Task <IActionResult> Index() { var listOperation = await _bo.ListNotDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var lst = new List <ProductModelViewModel>(); foreach (var item in listOperation.Result) { lst.Add(ProductModelViewModel.Parse(item)); } var bList = await GetBrandViewModels(listOperation.Result.Select(x => x.BrandId).Distinct().ToList()); ViewData["Brands"] = bList; var cList = await GetCategoryViewModels(listOperation.Result.Select(x => x.CategoryId).Distinct().ToList()); ViewData["Categories"] = cList; ViewData["Title"] = "Product Models"; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); return(View(lst)); }
private async Task <List <ProductModelViewModel> > GetProductModelViewModels(List <Guid> ids) { var filterOperation = await _pmbo.FilterAsync(x => ids.Contains(x.Id)); var eList = new List <ProductModelViewModel>(); foreach (var item in filterOperation.Result) { eList.Add(ProductModelViewModel.Parse(item)); } return(eList); }
public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(RecordNotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var getCOperation = await _cbo.ReadAsync(getOperation.Result.CategoryId); if (!getCOperation.Success) { return(OperationErrorBackToIndex(getCOperation.Exception)); } if (getCOperation.Result == null) { return(RecordNotFound()); } var getBOperation = await _bbo.ReadAsync(getOperation.Result.BrandId); if (!getBOperation.Success) { return(OperationErrorBackToIndex(getBOperation.Exception)); } if (getBOperation.Result == null) { return(RecordNotFound()); } var vm = ProductModelViewModel.Parse(getOperation.Result); Draw("Details", "fa-search"); ViewData["Brand"] = BrandViewModel.Parse(getBOperation.Result); ViewData["Category"] = CategoryViewModel.Parse(getCOperation.Result); return(View(vm)); }
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(RecordNotFound()); } var getEOperation = await _ebo.ReadAsync(getOperation.Result.EstablishmentId); if (!getEOperation.Success) { return(OperationErrorBackToIndex(getEOperation.Exception)); } if (getEOperation.Result == null) { return(RecordNotFound()); } var getSBOperation = await _sbbo.ReadAsync(getOperation.Result.ShoppingBasketId); if (!getSBOperation.Success) { return(OperationErrorBackToIndex(getSBOperation.Exception)); } if (getSBOperation.Result == null) { return(RecordNotFound()); } var getPMOperation = await _pmbo.ReadAsync(getOperation.Result.ProductModelId); if (!getPMOperation.Success) { return(OperationErrorBackToIndex(getPMOperation.Exception)); } if (getPMOperation.Result == null) { return(RecordNotFound()); } var getPOperation = await _pbo.ReadAsync(getSBOperation.Result.ProfileId); if (!getPOperation.Success) { return(OperationErrorBackToIndex(getPOperation.Exception)); } if (getPOperation.Result == null) { return(RecordNotFound()); } var getCOperation = await _cbo.ReadAsync(getEOperation.Result.CompanyId); if (!getCOperation.Success) { return(OperationErrorBackToIndex(getCOperation.Exception)); } if (getCOperation.Result == null) { return(RecordNotFound()); } var vm = ProductUnitViewModel.Parse(getOperation.Result); ViewData["Profile"] = ProfileViewModel.Parse(getPOperation.Result); ViewData["Company"] = CompanyViewModel.Parse(getCOperation.Result); ViewData["Establishment"] = EstablishmentViewModel.Parse(getEOperation.Result); ViewData["ShoppingBasket"] = ShoppingBasketViewModel.Parse(getSBOperation.Result); ViewData["ProductModel"] = ProductModelViewModel.Parse(getPMOperation.Result); Draw("Details", "fa-search"); return(View(vm)); }
private async Task <ProductModelViewModel> GetProductModelViewModel(Guid id) { var getOperation = await _pmbo.ReadAsync(id); return(ProductModelViewModel.Parse(getOperation.Result)); }
public async Task <IActionResult> Edit(Guid id, ProductModelViewModel vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync(id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var result = getOperation.Result; if (!vm.CompareToModel(result)) { result = vm.ToModel(result); var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception); getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } vm = ProductModelViewModel.Parse(getOperation.Result); var listBOperation = await _bbo.ListNotDeletedAsync(); if (!listBOperation.Success) { return(OperationErrorBackToIndex(listBOperation.Exception)); } var listCOperation = await _cbo.ListNotDeletedAsync(); if (!listCOperation.Success) { return(OperationErrorBackToIndex(listCOperation.Exception)); } ViewBag.Measure = Enum.GetNames(typeof(Measure)).Select(r => new SelectListItem { Text = r, Value = r });; var bList = new List <SelectListItem>(); foreach (var item in listBOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.BrandId) { listItem.Selected = true; } bList.Add(listItem); } ViewBag.Brands = bList; var cList = new List <SelectListItem>(); foreach (var item in listCOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.BrandId) { listItem.Selected = true; } cList.Add(listItem); } ViewBag.Categories = cList; Draw("Edit", "fa-edit"); return(View(vm)); } if (!updateOperation.Result) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Message); getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } vm = ProductModelViewModel.Parse(getOperation.Result); var listBOperation = await _bbo.ListNotDeletedAsync(); if (!listBOperation.Success) { return(OperationErrorBackToIndex(listBOperation.Exception)); } var listCOperation = await _cbo.ListNotDeletedAsync(); if (!listCOperation.Success) { return(OperationErrorBackToIndex(listCOperation.Exception)); } ViewBag.Measure = Enum.GetNames(typeof(Measure)).Select(r => new SelectListItem { Text = r, Value = r });; var bList = new List <SelectListItem>(); foreach (var item in listBOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.BrandId) { listItem.Selected = true; } bList.Add(listItem); } ViewBag.Brands = bList; var cList = new List <SelectListItem>(); foreach (var item in listCOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.BrandId) { listItem.Selected = true; } cList.Add(listItem); } ViewBag.Categories = cList; Draw("Edit", "fa-edit"); return(View(vm)); } else { return(OperationSuccess("The record was successfuly updated")); } } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(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(RecordNotFound()); } var vm = ProductModelViewModel.Parse(getOperation.Result); var listBOperation = await _bbo.ListNotDeletedAsync(); if (!listBOperation.Success) { return(OperationErrorBackToIndex(listBOperation.Exception)); } var listCOperation = await _cbo.ListNotDeletedAsync(); if (!listCOperation.Success) { return(OperationErrorBackToIndex(listCOperation.Exception)); } ViewBag.Measure = Enum.GetNames(typeof(Measure)).Select(r => new SelectListItem { Text = r, Value = r });; var bList = new List <SelectListItem>(); foreach (var item in listBOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.BrandId) { listItem.Selected = true; } bList.Add(listItem); } ViewBag.Brands = bList; var cList = new List <SelectListItem>(); foreach (var item in listCOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.BrandId) { listItem.Selected = true; } cList.Add(listItem); } ViewBag.Categories = cList; Draw("Edit", "fa-edit"); return(View(vm)); }