コード例 #1
0
ファイル: ContractVisaRepository.cs プロジェクト: rec2020/REC
        public bool RemoveContractVisa(int Id)
        {
            ContractVisa ContractVisa = GetContractVisaById(Id);

            if (ContractVisa == null)
            {
                return(false);
            }

            _context.Remove(ContractVisa);
            _context.SaveChanges();

            return(true);
        }
コード例 #2
0
ファイル: ContractVisaRepository.cs プロジェクト: rec2020/REC
        public int AddContractVisa(ContractVisa contractVisa)
        {
            _context.ContractVisas.Add(contractVisa);
            _context.SaveChanges();

            // Contract Info
            var cont = _context.Contracts.Find(contractVisa.ContractId);

            if (cont != null)
            {
                cont.ContractStatusId = (int)EnumHelper.ContractStatus.Visa;
                //cont.ContractStatusName = _context.ContractStatuses.Find(cont.ContractStatusId).Name;
                if (contractVisa.EmployeeId != null)
                {
                    cont.EmployeeId = contractVisa.EmployeeId;
                    //cont.EmployeeName = contractVisa.EmployeeName;
                }
                _context.Update(cont);
                _context.SaveChanges();
            }



            // Adding To Contract History
            ContractHistory history = new ContractHistory();

            history.ContractId       = contractVisa.ContractId;
            history.CustomerId       = cont.CustomerId;
            history.ForeignAgencyId  = cont.ForeignAgencyId;
            history.EmployeeId       = cont.EmployeeId;
            history.ActionId         = (int)EnumHelper.ContractAction.Visa;
            history.ContractStatusId = cont.ContractStatusId;
            history.ActionById       = contractVisa.VisaById;
            history.ActionByName     = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
            var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);

            if (foreignAgencies != null)
            {
                history.ForeignAgencyName = foreignAgencies.OfficeName;
            }
            var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);

            if (cust != null)
            {
                history.CustomerName = cust.Name;
            }
            var emp = _context.Employees.SingleOrDefault(x => x.Id == history.EmployeeId);

            if (emp != null)
            {
                history.EmployeeName = emp.FirstName + ' ' + emp.Father;
            }
            history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);;

            _context.ContractHistories.Add(history);
            _context.SaveChanges();


            return(contractVisa.Id);
        }