Ejemplo n.º 1
0
        public async Task <IActionResult> GetBranch(int id)
        {
            var branch = await branchService.FindAsync(id);

            if (branch == null)
            {
                return(NotFound());
            }

            var mappedBranch = mapper.Map <Branch, BranchViewModel>(branch);

            return(Ok(mappedBranch));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            await OnGet();

            //Validate From [Check for requred fields and errors then populate the corresponding message]
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            //var branch =  new Branch();//if doesnt exist create a new one
            var branch = await branchService.FindAsync(Branch.Id) ?? new Branch();//if t doesnt exist create a new one

            if (branches.FirstOrDefault(x => x.Name == Branch.Name) != null && branch.Id != branches.FirstOrDefault(x => x.Name == Branch.Name).Id)
            {
                ModelState.AddModelError("Branch.Name", "Branch Already Exists");
                await OnGet();

                return(Page());
            }
            //get data from the Bind Property Model
            branch.Name       = Branch.Name;
            branch.Location   = Branch.Location;
            branch.BusinessId = Id.Value;



            await branchService.SaveAsync(branch);

            return(RedirectToPage());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (Id.HasValue)
            {
                titlesList = branchItemService.GetAllAsync().Result.Select(x => x.DocumentTitle).Distinct().ToList();
                titlesList.Add("سجل تجاري");
                titlesList.Add("رخصة");
                titlesList.Add("عقد النفايات");
                titles      = titlesList.Distinct().ToArray();
                branchItems = branchItemService.GetAllAsync().Result.Where(x => x.BranchId == Id.Value).ToList();
                var _branchService = await branchService.FindAsync(Id.Value);

                if (_branchService != null)
                {
                    viewContent.BranchName   = _branchService.Name;
                    viewContent.BusnissId    = _branchService.BusinessId;
                    viewContent.BusinessName = _branchService.Business.Name;
                    viewContent.BranchId     = _branchService.Id;
                    return(null);
                }

                RedirectToPage("/Index");
            }
            return(RedirectToPage("/Index"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetOifAutoPopulate(int id)
        {
            var branch = await branchService.FindAsync(id);

            if (branch == null)
            {
                return(Ok());
            }

            var mapped = mapper.Map <Branch, OIFAutoPopulateFields>(branch);

            return(Ok(mapped));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnGet()
        {
            if (Id.HasValue)
            {
                branchItems = branchItemService.GetAllAsync().Result.Where(x => x.BranchId == Id.Value).ToList();
                var _branchService = await branchService.FindAsync(Id.Value);

                if (branchItems != null && _branchService != null)
                {
                    viewContent.BranchName   = _branchService.Name;
                    viewContent.BusnissId    = _branchService.BusinessId;
                    viewContent.BusinessName = _branchService.Business.Name;
                    viewContent.BranchId     = _branchService.Id;
                    return(null);
                }
                RedirectToPage("/Index");
            }
            return(RedirectToPage("/Index"));
        }