コード例 #1
0
        public IActionResult Index(int ContractId)
        {
            ContractSelectViewModel select = new ContractSelectViewModel
            {
                ContractId = ContractId
            };
            var contractSelectList = _select.GetContractSelects().Where(x => x.ContractId == ContractId);

            ViewBag.ContractSelect  = contractSelectList;
            ViewBag.ForeignAgencyId = new SelectList(_agency.GetAgencies(), "Id", "OfficeName");
            return(View(select));
        }
コード例 #2
0
        public IActionResult Add(ContractSelectViewModel selectViewModel)
        {
            selectViewModel.SelectByName = User.Identity.Name;
            var selectById = _user.GetUserByName(selectViewModel.SelectByName);

            selectViewModel.SelectById = selectById.Id;
            var contractSelectList = _select.GetContractSelects().Where(x => x.ContractId == selectViewModel.ContractId);

            ViewBag.ContractSelect  = contractSelectList;
            ViewBag.ForeignAgencyId = new SelectList(_agency.GetAgencies(), "Id", "OfficeName", selectViewModel.ForeignAgencyId);
            if (selectViewModel.ForeignAgencyId == null)
            {
                ModelState.AddModelError("", "الرجاء تحديد الوكالة الخارجية");
            }
            if (selectViewModel.Id == 0)
            {
                ModelState.Remove("Id");
                ModelState.Remove("ForeignAgencyId");
                if (ModelState.IsValid)
                {
                    var selectcontract = _mapper.Map <ContractSelect>(selectViewModel);
                    _select.AddContractSelect(selectcontract);
                    _toastNotification.AddSuccessToastMessage("تم الاختيار بنجاح");
                    return(RedirectToAction(nameof(Index), new { ContractId = selectViewModel.ContractId }));
                }
                return(View(nameof(Index), selectViewModel));
            }
            else
            {
                ModelState.Remove("ForeignAgencyId");
                if (ModelState.IsValid)
                {
                    var selectcontract = _mapper.Map <ContractSelect>(selectViewModel);
                    _select.UpdateContractSelect(selectViewModel.Id, selectcontract);
                    _toastNotification.AddSuccessToastMessage("تم تعديل الاختيار بنجاح");
                    return(RedirectToAction(nameof(Index), new { ContractId = selectViewModel.ContractId }));
                }
                return(View(nameof(Index), selectViewModel));
            }
        }