private async Task <List <BrandViewModel> > GetBrandViewModels(List <Guid> ids)
        {
            var filterOperation = await _bbo.FilterAsync(x => ids.Contains(x.Id));

            var drList = new List <BrandViewModel>();

            foreach (var item in filterOperation.Result)
            {
                drList.Add(BrandViewModel.Parse(item));
            }
            return(drList);
        }
        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));
        }
示例#3
0
        public async Task <IActionResult> Index()
        {
            var listOperation = await _bo.ListNotDeletedAsync();

            if (!listOperation.Success)
            {
                return(OperationErrorBackToIndex(listOperation.Exception));
            }

            var lst = new List <BrandViewModel>();

            foreach (var item in listOperation.Result)
            {
                lst.Add(BrandViewModel.Parse(item));
            }

            ViewData["Title"]       = "Brands";
            ViewData["BreadCrumbs"] = GetCrumbs();
            ViewData["DeleteHref"]  = GetDeleteRef();

            return(View(lst));
        }
示例#4
0
        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 vm = BrandViewModel.Parse(getOperation.Result);

            Draw("Details", "fa-search");

            return(View(vm));
        }
示例#5
0
        public async Task <IActionResult> Edit(Guid id, BrandViewModel 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);
                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = BrandViewModel.Parse(getOperation.Result);
                        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 = BrandViewModel.Parse(getOperation.Result);
                        Draw("Edit", "fa-edit");
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        private async Task <BrandViewModel> GetBrandViewModel(Guid id)
        {
            var getOperation = await _bbo.ReadAsync(id);

            return(BrandViewModel.Parse(getOperation.Result));
        }