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);
        }
Esempio n. 2
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 = RegionViewModel.Parse(getOperation.Result);

            ViewData["Title"] = "Region";

            var crumbs = GetCrumbs();

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

            ViewData["BreadCrumbs"] = crumbs;
            return(View(vm));
        }
 private async Task<List<RegionViewModel>> GetRegionViewModels(List<Guid> ids)
 {
     var filterOperation = await _rbo.FilterAsync(x => ids.Contains(x.Id));
     var rList = new List<RegionViewModel>();
     foreach (var item in filterOperation.Result)
     {
         rList.Add(RegionViewModel.Parse(item));
     }
     return rList;
 }
Esempio n. 4
0
        public ActionResult <List <RegionViewModel> > List()
        {
            var res = _bo.List();

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

            foreach (var item in res.Result)
            {
                list.Add(RegionViewModel.Parse(item));
            }
            return(list);
        }
Esempio n. 5
0
        public ActionResult <RegionViewModel> Get(Guid id)
        {
            var res = _bo.Read(id);

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

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

            var lst = new List <RegionViewModel>();

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

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

            return(View(lst));
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(Guid id, RegionViewModel 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 = RegionViewModel.Parse(getOperation.Result);
                        ViewData["Title"] = "Edit Region";
                        var crumbs = GetCrumbs();
                        crumbs.Add(new BreadCrumb()
                        {
                            Action = "Edit", Controller = "Regions", Icon = "fa-search", Text = "Edit"
                        });
                        ViewData["BreadCrumbs"] = crumbs;
                        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 = RegionViewModel.Parse(getOperation.Result);
                        ViewData["Title"] = "Edit Region";
                        var crumbs = GetCrumbs();
                        crumbs.Add(new BreadCrumb()
                        {
                            Action = "Edit", Controller = "Regions", Icon = "fa-search", Text = "Edit"
                        });
                        ViewData["BreadCrumbs"] = crumbs;
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }