Пример #1
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound("Nebylo zadáno 'id' pro vyhledání rámcové smlouvy."));
            }

            Contract contract = await _db.Contracts
                                .Include(x => x.SharedInfo)
                                .FirstOrDefaultAsync(x => x.ContractsId == id);

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

            EditContractViewModel vm = new EditContractViewModel();

            vm.Contract = contract;

            vm.Audits = await getAuditViewModelAsync(_db, "Contracts", (int)id);

            await populateModelAsync(vm);

            vm.CreatedOrders = _db.Order.Include(x => x.Contract).Where(x => x.ContractId == id).ToList();

            return(View(vm));
        }
Пример #2
0
        public async Task <IActionResult> ContractDetails(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var contract = await _context.Contract
                           .Include(c => c.IdEmployeeNavigation)
                           .Include(c => c.IdContractStatusNavigation)
                           .Include(c => c.IdContractTypeNavigation)
                           .FirstOrDefaultAsync(m => m.IdContract == id);

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

            var nettoSalary = Decimal.Multiply(contract.Salary, 0.696M);


            var benefits = from b in _context.Benefit
                           select new
            {
                b.IdBenefit,
                b.Name,
                b.Price,
                IsSelected = ((from cb in _context.ContractBenefit
                               where (cb.IdContract == id) & (cb.IdBenefit == b.IdBenefit)
                               select cb).Count() > 0)
            };

            decimal benefitsValue = 0.0M;

            var editContractViewModel = new EditContractViewModel();

            editContractViewModel.Contract    = contract;
            editContractViewModel.NettoSalary = nettoSalary;

            var benefitCheckBox = new List <BenefitCheckBoxViewModel>();

            foreach (var item in benefits)
            {
                benefitCheckBox.Add(new BenefitCheckBoxViewModel {
                    IdBenefit = item.IdBenefit, BenefitName = item.Name, IsSelected = item.IsSelected
                });
                if (item.IsSelected == true)
                {
                    benefitsValue += item.Price;
                }
            }

            editContractViewModel.Benefits      = benefitCheckBox;
            editContractViewModel.BenefitsValue = benefitsValue;
            editContractViewModel.FinalSalary   = nettoSalary - benefitsValue;

            return(View(editContractViewModel));
        }
 public EditContractWindow(Contract contract)
 {
     InitializeComponent();
     ViewModel   = new EditContractViewModel(contract);
     DataContext = ViewModel;
     Title       = contract.ProjectName;
     ViewModel.AddPopupAction    = AddPopup;
     ViewModel.RemovePopupAction = RemovePopup;
 }
Пример #4
0
        public IActionResult VerifyContractNoForEdit([Bind(include: "Id,No")] EditContractViewModel model)
        {
            string message = null;
            var    result  = IsUnique(model.Id, model.No);

            if (!result)
            {
                message = "已存在合同编号:" + model.No;
                return(Json(message));
            }
            else
            {
                return(Json(true));
            }
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, EditContractViewModel model)
        {
            if (id != model.Contract.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.CounterpartiesId != null)
                    {
                        for (int i = 0; i < model.CounterpartiesId.Count; i++)
                        {
                            ContractCounterparty contractCounterparty = new ContractCounterparty()
                            {
                                ContractId     = id,
                                CounterpartyId = model.CounterpartiesId[i]
                            };
                            if (!_context.ContractCounterparties.ToList().Exists(c => c.ContractId == contractCounterparty.ContractId &&
                                                                                 c.CounterpartyId == contractCounterparty.CounterpartyId))
                            {
                                _context.ContractCounterparties.Add(contractCounterparty);
                                await _context.SaveChangesAsync();
                            }
                        }
                    }
                    _context.Update(model.Contract);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContractExists(model.Contract.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", new { id = id }));
            }
            return(View(model.Contract));
        }
Пример #6
0
        public async Task <IActionResult> Edit(EditContractViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await _mainRepository.EditAsync(new Contract
                {
                    Id                       = model.Id,
                    No                       = model.No,
                    Name                     = model.Name,
                    Amount                   = model.Amount,
                    SignedDate               = model.SignedDate,
                    Deadline                 = model.Deadline,
                    PromisedDeadline         = model.PromisedDeadline,
                    JobContent               = model.JobContent,
                    ProjectLocation          = model.ProjectLocation,
                    Client                   = model.Client,
                    ClientContactPerson      = model.ClientContactPerson,
                    ClientContactPersonPhone = model.ClientContactPersonPhone,
                    AcceptWay                = (int)(model.AcceptWay),
                    SignStatus               = (int)(model.SignStatus),
                    AcceptStaffId            = model.AcceptStaffId,
                    ResponseStaffId          = model.ResponseStaffId,
                });

                TempData["globalMessage"] = "修改成功";
            }
            catch (DbUpdateException) //DbUpdateException /* ex */
            {
                //throw ex;
                ModelState.AddModelError("", "无法保存更改。 " +
                                         "请重试, 如果该问题仍然存在 " +
                                         "请联系系统管理员。");
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #7
0
        // GET: Contracts/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            EditContractViewModel model = new EditContractViewModel()
            {
                Contract = await _context.Contracts
                           .SingleOrDefaultAsync(m => m.Id == id),
                Counterparties     = _context.ContractCounterparties.Include(s => s.Counterparty).Where(c => c.ContractId == id).Select(s => s.Counterparty).ToList(),
                Properties         = new SelectList(_context.Properties, "Id", "Name"),
                ContractProperties = _context.ContractPropertieses.Include(c => c.Property).Where(c => c.ContractId == id).ToList()
            };

            model.Individuals             = _context.Individuals.Where(i => i.IsBlocked == false).ToList();
            model.IndividualEntrepreneurs = _context.IndividualEntrepreneurs.Where(e => e.IsBlocked == false).ToList();
            model.Companies     = _context.Companies.Where(c => c.IsBlocked == false).ToList();
            ViewData["Country"] = new SelectList(Country.GetCountryList());
            return(View(model));
        }
Пример #8
0
        public async Task <IActionResult> Edit(EditContractViewModel model)
        {
            //AsNoTracking
            if (!IsUnique(model.Id, model.No))
            {
                ModelState.AddModelError("No", "已存在合同编号:" + model.No);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var contract = _contractRepository.EntityItems.Where(x => x.Id == model.Id).FirstOrDefault();

            contract.Name           = model.Name;
            contract.No             = model.No;
            contract.JobContent     = model.JobContent;
            contract.Amount         = model.Amount;
            contract.SignedDate     = model.SignedDate;
            contract.Deadline       = model.Deadline;
            contract.FinishDateTime = model.FinishDateTime;
            contract.AcceptUserId   = model.AcceptUserId;
            contract.UserId         = model.UserId;
            contract.UserName       = model.UserName;

            try
            {
                await _contractRepository.EditAsync(contract);

                //StatusMessage = $"成功编辑\"参与人员\"{model.StaffName}";
                StatusMessage = $"成功编辑\"合同\"";
            }
            catch (Exception ex)
            {
                throw;
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #9
0
        public async Task <IActionResult> EditContract(EditContractViewModel editContract)//int id, Contract contract, int[] IdsBenefits)
        {
            //var result = from b in context.Benefit
            //             select new
            //             {
            //                 b.IdBenefit,
            //                 b.Name,
            //                 IsSelected = ((from cb in context.ContractBenefit
            //                                where (cb.IdContract == id) & (cb.IdBenefit == b.IdBenefit)
            //                                select cb).Count() > 0)
            //             };

            //var benefitCheckBox = new List<BenefitCheckBoxViewModel>();

            //foreach (var item in result)
            //{
            //    benefitCheckBox.Add(new BenefitCheckBoxViewModel { IdBenefit = item.IdBenefit, BenefitName = item.Name, IsSelected = item.IsSelected });
            //}

            ViewData["IdContractStatus"] = new SelectList(_context.ContractStatus, "IdContractStatus", "StatusName");
            ViewData["IdContractType"]   = new SelectList(_context.ContractType, "IdContractType", "ContractTypeName");
            //ViewData["IdEmployee"] = new SelectList(_context.Employee.OrderBy(x => x.LastName), "Id", "Email");
            //ViewData["Benefits"] = benefitCheckBox;
            var EmpQuery = _context.Employee.OrderBy(x => x.LastName).Select(x => new
            {
                Id       = x.Id,
                FullName = x.LastName + " " + x.FirstName
            });

            ViewData["IdEmployee"] = new SelectList(EmpQuery, "Id", "FullName");

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(editContract.Contract);
                    //Adding Benefits To Contract
                    //foreach (int idBenefit in IdsBenefits)
                    //{
                    //    ContractBenefit contractBenefit = new ContractBenefit
                    //    {
                    //        IdContract = contract.IdContract,
                    //        IdBenefit = idBenefit
                    //    };
                    //    context.ContractBenefit.Add(contractBenefit);
                    //}

                    foreach (var item in _context.ContractBenefit)
                    {
                        if (item.IdContract == editContract.Contract.IdContract)
                        {
                            _context.Entry(item).State = EntityState.Deleted;
                        }
                    }

                    foreach (var item in editContract.Benefits)
                    {
                        if (item.IsSelected)
                        {
                            _context.ContractBenefit.Add(new ContractBenefit()
                            {
                                IdContract = editContract.Contract.IdContract,
                                IdBenefit  = item.IdBenefit
                            });
                        }
                    }



                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContractExists(editContract.Contract.IdContract))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(ListAllContracts)));
            }

            return(View(editContract));
        }
Пример #10
0
        public async Task <IActionResult> EditContract(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var contract = await _context.Contract.FindAsync(id);

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

            var result = from b in _context.Benefit
                         orderby b.Name
                         select new
            {
                b.IdBenefit,
                b.Name,
                b.Price,
                IsSelected = ((from cb in _context.ContractBenefit
                               where (cb.IdContract == id) & (cb.IdBenefit == b.IdBenefit)
                               select cb).Count() > 0)
            };

            var editContractViewModel = new EditContractViewModel();

            /*editContractViewModel.IdContract = id.Value;
             * editContractViewModel.Salary = contract.Salary;
             * editContractViewModel.ContractStart = contract.ContractStart;
             * editContractViewModel.ContractEnd = contract.ContractEnd;*/
            editContractViewModel.Contract = contract;

            var benefitCheckBox = new List <BenefitCheckBoxViewModel>();

            foreach (var item in result)
            {
                //var benefitCheckBoxViewModel = new BenefitCheckBoxViewModel
                //{
                //    IdBenefit = benefit.IdBenefit,
                //    BenefitName = benefit.Name
                //};
                benefitCheckBox.Add(new BenefitCheckBoxViewModel {
                    IdBenefit = item.IdBenefit, BenefitName = item.Name, Price = item.Price, IsSelected = item.IsSelected
                });
            }



            ViewData["IdContractStatus"] = new SelectList(_context.ContractStatus, "IdContractStatus", "StatusName");
            ViewData["IdContractType"]   = new SelectList(_context.ContractType, "IdContractType", "ContractTypeName");
            //ViewData["IdEmployee"] = new SelectList(_context.Employee.OrderBy(x => x.LastName), "Id", "Email");
            //ViewData["Benefits"] = benefitCheckBox; //context.Benefit;

            var EmpQuery = _context.Employee.OrderBy(x => x.LastName).Select(x => new
            {
                Id       = x.Id,
                FullName = x.LastName + " " + x.FirstName
            });

            ViewData["IdEmployee"] = new SelectList(EmpQuery, "Id", "FullName");

            editContractViewModel.Benefits = benefitCheckBox;

            return(View(editContractViewModel));
        }
Пример #11
0
        public async Task <IActionResult> Edit(string actionType, int id, EditContractViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                TempData["Error"] = "Něco se porouchalo...";
                vm.Audits         = await getAuditViewModelAsync(_db, "Contracts", (int)id);
                await populateModelAsync(vm);

                return(View(vm));
            }

            // Check if there was a change in old/current model
            EditContractViewModel oldVm = new EditContractViewModel();

            oldVm.Contract = await _db.Contracts
                             .Include(x => x.SharedInfo)
                             .AsNoTracking()
                             .FirstOrDefaultAsync(x => x.ContractsId == vm.Contract.ContractsId);

            if (oldVm.Contract.ContractName == vm.Contract.ContractName &&
                oldVm.Contract.SharedInfo.ReceiveDate == vm.Contract.SharedInfo.ReceiveDate &&
                oldVm.Contract.SharedInfo.Subject == vm.Contract.SharedInfo.Subject &&
                oldVm.Contract.SharedInfo.EveDivision == vm.Contract.SharedInfo.EveDivision &&
                oldVm.Contract.SharedInfo.EveDepartment == vm.Contract.SharedInfo.EveDepartment &&
                oldVm.Contract.SharedInfo.EveCreatedUser == vm.Contract.SharedInfo.EveCreatedUser &&
                oldVm.Contract.SharedInfo.ContactId == vm.Contract.SharedInfo.ContactId &&
                oldVm.Contract.SharedInfo.CompanyId == vm.Contract.SharedInfo.CompanyId &&
                oldVm.Contract.SharedInfo.Price == vm.Contract.SharedInfo.Price &&
                oldVm.Contract.SharedInfo.CurrencyId == vm.Contract.SharedInfo.CurrencyId &&
                oldVm.Contract.SharedInfo.ExchangeRate == vm.Contract.SharedInfo.ExchangeRate &&
                oldVm.Contract.Notes == vm.Contract.Notes &&
                oldVm.Contract.Active == vm.Contract.Active)
            {
                TempData["Info"] = "Nebyla provedena změna, není co uložit";
                vm.Audits        = await getAuditViewModelAsync(_db, "Contracts", (int)id);
                await populateModelAsync(vm);

                vm.Contract.SharedInfo = await _db.SharedInfo
                                         .Where(x => x.SharedInfoId == vm.Contract.SharedInfoId)
                                         .Include(x => x.Company)
                                         .Include(x => x.Contact)
                                         .FirstOrDefaultAsync();

                return(View(vm));
            }

            if (vm.Contract.SharedInfo.Price != null)
            {
                vm.Contract.SharedInfo.PriceCzk = Convert.ToInt32(vm.Contract.SharedInfo.Price * vm.Contract.SharedInfo.ExchangeRate);  // 1000 * 26,243
            }
            else
            {
                vm.Contract.SharedInfo.PriceCzk     = null;
                vm.Contract.SharedInfo.ExchangeRate = null;
            }
            vm.Contract.ModifiedBy   = User.GetLoggedInUserName();
            vm.Contract.ModifiedDate = DateTime.Now;

            _db.Update(vm.Contract);
            await _db.SaveChangesAsync(vm.Contract.ModifiedBy);

            TempData["Success"] = "Editace uložena";

            // Save
            if (actionType == "Uložit")
            {
                vm.Audits = await getAuditViewModelAsync(_db, "Contracts", (int)id);
                await populateModelAsync(vm);

                return(View(vm));
            }
            // Save & Exit
            else
            {
                return(RedirectToAction(nameof(Index)));
            }
        }