public async Task<IActionResult> Edit(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 = EstablishmentViewModel.Parse(getOperation.Result);

            var listROperation = await _rbo.ListNotDeletedAsync();
            if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception);
            var rList = new List<SelectListItem>();
            foreach (var item in listROperation.Result)
            {
                var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name };
                if (item.Id == vm.RegionId) listItem.Selected = true;
                rList.Add(listItem);
            }
            ViewBag.Regions = rList;

            var listCOperation = await _cbo.ListNotDeletedAsync();
            if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception);
            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.CompanyId) listItem.Selected = true;
                cList.Add(listItem);
            }
            ViewBag.Companies = cList;

            Draw("Edit", "fa-edit");
            return View(vm);
        }
        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 getROperation = await _rbo.ReadAsync(getOperation.Result.RegionId);
            if (!getROperation.Success) return OperationErrorBackToIndex(getROperation.Exception);
            if (getROperation.Result == null) return RecordNotFound();

            var getCOperation = await _cbo.ReadAsync(getOperation.Result.CompanyId);
            if (!getCOperation.Success) return OperationErrorBackToIndex(getCOperation.Exception);
            if (getCOperation.Result == null) return RecordNotFound();

            var vm = EstablishmentViewModel.Parse(getOperation.Result);
            ViewData["Title"] = "Establishment";

            var crumbs = GetCrumbs();
            crumbs.Add(new BreadCrumb() { Action = "Details", Controller = "Establishments", Icon = "fa-search", Text = "Detail" });

            ViewData["Region"] = RegionViewModel.Parse(getROperation.Result);
            ViewData["Company"] = CompanyViewModel.Parse(getCOperation.Result);
            ViewData["BreadCrumbs"] = crumbs;
            return View(vm);
        }
        private async Task <List <EstablishmentViewModel> > GetEstablishmentViewModels(List <Guid> ids)
        {
            var filterOperation = await _ebo.FilterAsync(x => ids.Contains(x.Id));

            var eList = new List <EstablishmentViewModel>();

            foreach (var item in filterOperation.Result)
            {
                eList.Add(EstablishmentViewModel.Parse(item));
            }
            return(eList);
        }
        public async Task <IActionResult> Index()
        {
            var listOperation = await _bo.ListNotDeletedAsync();

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

            var lst = new List <ReservedQueueViewModel>();

            foreach (var item in listOperation.Result)
            {
                var limitCheck = await _bo.TwoHourLimitReserveAsync(item.Id);

                if (limitCheck.Result && limitCheck.Success)
                {
                    lst.Add(ReservedQueueViewModel.Parse(item));
                }
            }

            var listEOperation = await _ebo.ListNotDeletedAsync();

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

            var elst = new List <EstablishmentViewModel>();

            foreach (var item in listEOperation.Result)
            {
                elst.Add(EstablishmentViewModel.Parse(item));
            }

            var estList = await GetEstablishmentViewModels(listOperation.Result.Select(x => x.EstablishmentId).Distinct().ToList());

            var profiList = await GetProfileViewModels(listOperation.Result.Select(x => x.ProfileId).Distinct().ToList());

            var cList = await GetCompanyViewModels(listEOperation.Result.Select(x => x.CompanyId).Distinct().ToList());

            ViewData["Companies"]      = cList;
            ViewData["Establishments"] = estList;
            ViewData["Profiles"]       = profiList;
            ViewData["Title"]          = "Reserved Queues";
            ViewData["BreadCrumbs"]    = GetCrumbs();
            ViewData["DeleteHref"]     = GetDeleteRef();

            return(View(lst));
        }
        public ActionResult <List <EstablishmentViewModel> > List()
        {
            var res = _bo.List();

            if (!res.Success)
            {
                return(InternalServerError());
            }
            var list = new List <EstablishmentViewModel>();

            foreach (var establishment in res.Result)
            {
                list.Add(EstablishmentViewModel.Parse(establishment));
            }
            return(list);
        }
        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 getDrOperation = await _ebo.ReadAsync(getOperation.Result.EstablishmentId);

            if (!getDrOperation.Success)
            {
                return(OperationErrorBackToIndex(getDrOperation.Exception));
            }
            if (getDrOperation.Result == null)
            {
                return(RecordNotFound());
            }

            var getCOperation = await _cbo.ReadAsync(getDrOperation.Result.CompanyId);

            if (!getCOperation.Success)
            {
                return(OperationErrorBackToIndex(getCOperation.Exception));
            }
            if (getCOperation.Result == null)
            {
                return(RecordNotFound());
            }

            var vm = StoreQueueViewModel.Parse(getOperation.Result);

            ViewData["Company"]       = CompanyViewModel.Parse(getCOperation.Result);
            ViewData["Establishment"] = EstablishmentViewModel.Parse(getDrOperation.Result);
            Draw("Details", "fa-search");
            return(View(vm));
        }
        public ActionResult <EstablishmentViewModel> Get(Guid id)
        {
            var res = _bo.Read(id);

            if (res.Success)
            {
                if (res.Result == null)
                {
                    return(NotFound());
                }
                var vm = EstablishmentViewModel.Parse(res.Result);
                return(vm);
            }
            else
            {
                return(InternalServerError());
            }
        }
        public async Task <IActionResult> Index()
        {
            var listOperation = await _bo.ListNotDeletedAsync();

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

            var lst = new List <StoreQueueViewModel>();

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

            var listEOperation = await _ebo.ListNotDeletedAsync();

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

            var elst = new List <EstablishmentViewModel>();

            foreach (var item in listEOperation.Result)
            {
                elst.Add(EstablishmentViewModel.Parse(item));
            }

            var drList = await GetEstablishmentViewModels(listOperation.Result.Select(x => x.EstablishmentId).Distinct().ToList());

            var cList = await GetCompanyViewModels(listEOperation.Result.Select(x => x.CompanyId).Distinct().ToList());

            ViewData["Companies"]      = cList;
            ViewData["Establishments"] = drList;
            ViewData["Title"]          = "Store Queues";
            ViewData["BreadCrumbs"]    = GetCrumbs();
            ViewData["DeleteHref"]     = GetDeleteRef();

            return(View(lst));
        }
        private async Task <EstablishmentViewModel> GetEstablishmentViewModel(Guid id)
        {
            var getOperation = await _ebo.ReadAsync(id);

            return(EstablishmentViewModel.Parse(getOperation.Result));
        }
        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));
        }
        public async Task <IActionResult> Index()
        {
            var listOperation = await _bo.ListNotDeletedAsync();

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

            var lst = new List <ProductUnitViewModel>();

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

            var listEOperation = await _ebo.ListNotDeletedAsync();

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

            var elst = new List <EstablishmentViewModel>();

            foreach (var item in listEOperation.Result)
            {
                elst.Add(EstablishmentViewModel.Parse(item));
            }

            var listSBOperation = await _sbbo.ListNotDeletedAsync();

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

            var sblst = new List <ShoppingBasketViewModel>();

            foreach (var item in listSBOperation.Result)
            {
                sblst.Add(ShoppingBasketViewModel.Parse(item));
            }

            var eList = await GetEstablishmentViewModels(listOperation.Result.Select(x => x.EstablishmentId).Distinct().ToList());

            var sbList = await GetShoppingBasketViewModels(listOperation.Result.Select(x => x.ShoppingBasketId).Distinct().ToList());

            var pmList = await GetProductModelViewModels(listOperation.Result.Select(x => x.ProductModelId).Distinct().ToList());

            var cList = await GetCompanyViewModels(listEOperation.Result.Select(x => x.CompanyId).Distinct().ToList());

            var pList = await GetProfileViewModels(listSBOperation.Result.Select(x => x.ProfileId).Distinct().ToList());

            ViewData["Profiles"]        = pList;
            ViewData["Companies"]       = cList;
            ViewData["Establishments"]  = eList;
            ViewData["ShoppingBaskets"] = sbList;
            ViewData["ProductModels"]   = pmList;

            ViewData["Title"]       = "Product Units";
            ViewData["BreadCrumbs"] = GetCrumbs();
            ViewData["DeleteHref"]  = GetDeleteRef();
            return(View(lst));
        }
        public async Task<IActionResult> Edit(Guid id, EstablishmentViewModel 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();

                        var listROperation = await _rbo.ListNotDeletedAsync();
                        if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception);
                        var rList = new List<SelectListItem>();
                        foreach (var item in listROperation.Result)
                        {
                            var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name };
                            if (item.Id == vm.RegionId) listItem.Selected = true;
                            rList.Add(listItem);
                        }
                        ViewBag.Regions = rList;

                        var listCOperation = await _cbo.ListNotDeletedAsync();
                        if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception);
                        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.CompanyId) listItem.Selected = true;
                            cList.Add(listItem);
                        }
                        ViewBag.Companies = cList;

                        vm = EstablishmentViewModel.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();
                        var listROperation = await _rbo.ListNotDeletedAsync();
                        if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception);
                        var rList = new List<SelectListItem>();
                        foreach (var item in listROperation.Result)
                        {
                            var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name };
                            if (item.Id == vm.RegionId) listItem.Selected = true;
                            rList.Add(listItem);
                        }
                        ViewBag.Regions = rList;

                        var listCOperation = await _cbo.ListNotDeletedAsync();
                        if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception);
                        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.CompanyId) listItem.Selected = true;
                            cList.Add(listItem);
                        }
                        ViewBag.Companies = cList;

                        vm = EstablishmentViewModel.Parse(getOperation.Result);

                        Draw("Edit", "fa-edit");
                        return View(vm);
                    }
                    else return OperationSuccess("The record was successfuly updated");
                }
            }
            return RedirectToAction(nameof(Index));
        }