Exemple #1
0
        public static bool MakeContract(int clientId, int agentId, int builderId, int projectId)
        {
            ContractRepository contractRepository = new ContractRepository();
            int contractId;

            try
            {
                contractId = contractRepository.GetAll().Last().id;
            }
            catch
            {
                contractId = 1;
                contractRepository.Add(new Contract(contractId,
                                                    new ClientRepository().GetItem(clientId),
                                                    new AgentRepository().GetItem(agentId),
                                                    new BuilderRepository().GetItem(builderId),
                                                    new ProjectRepository().GetItem(projectId)));
                return(true);
            }
            contractId = contractId + 1;
            contractRepository.Add(new Contract(contractId,
                                                new ClientRepository().GetItem(clientId),
                                                new AgentRepository().GetItem(agentId),
                                                new BuilderRepository().GetItem(builderId),
                                                new ProjectRepository().GetItem(projectId)));
            return(true);
        }
 public static bool MakeContract(int clientId, int agentId, int builderId, int projectId)
 {
     ContractRepository contractRepository = new ContractRepository();
     int contractId;
     try
     {
         contractId = contractRepository.GetAll().Last().id;
     }
     catch
     {
         contractId = 1;
         contractRepository.Add( new Contract(contractId,
                                 new ClientRepository().GetItem(clientId),
                                 new AgentRepository().GetItem(agentId),
                                 new BuilderRepository().GetItem(builderId),
                                 new ProjectRepository().GetItem(projectId)));
         return true;
     }
     contractId = contractId + 1;
     contractRepository.Add(new Contract(contractId,
                            new ClientRepository().GetItem(clientId),
                            new AgentRepository().GetItem(agentId),
                            new BuilderRepository().GetItem(builderId),
                            new ProjectRepository().GetItem(projectId)));
     return true;
 }
        public void ContractRepositoryTest()
        {
            ContractRepository repository       = new ContractRepository();
            Contract           expectedContract = new Contract
            {
                agentId   = 10,
                builderId = 10,
                clientId  = 10,
                projectId = 10
            };

            repository.Add(expectedContract);


            Contract realContract = repository.GetAll().Last();

            Assert.AreEqual(expectedContract, realContract);

            repository.Delete(realContract);


            realContract = repository.GetAll().Last();

            Assert.AreNotEqual(expectedContract, realContract);
        }
Exemple #4
0
 public void CreateContract([FromQuery] Contract con)
 {
     if (ModelState.IsValid)
     {
         contractRepository.Add(con);
     }
 }
        public static bool MakeContract(int clientId, int agentId, int builderId, int projectId)
        {
            ContractRepository contractRepository = new ContractRepository();

            Contract contract = new Contract();
            contract.agentId = agentId;
            contract.clientId = clientId;
            contract.builderId = builderId;
            contract.projectId = projectId;

            contractRepository.Add(contract);

            return true;
        }
Exemple #6
0
        public void ContractRepository_DeleteContract_ShouldRemoveContract()
        {
            var contract = GetContract();

            var repository = new ContractRepository();

            repository.Add(contract);

            Assert.IsNotNull(repository.Get(contract.ContractNumber));

            repository.DeleteContract(contract.ContractNumber);

            Assert.IsNull(repository.Get(contract.ContractNumber));
        }
Exemple #7
0
        public static bool MakeContract(int clientId, int agentId, int builderId, int projectId)
        {
            ContractRepository contractRepository = new ContractRepository();

            Contract contract = new Contract();

            contract.agentId   = agentId;
            contract.clientId  = clientId;
            contract.builderId = builderId;
            contract.projectId = projectId;

            contractRepository.Add(contract);

            return(true);
        }
Exemple #8
0
        public void ContractRepository_GetProfileValue_ShouldGetTotalProfileValueForASingleContract()
        {
            // arrange
            var contract = GetContract();

            var repository = new ContractRepository();

            repository.Add(contract);

            // act
            var actual = repository.GetProfileValue(contract.ContractNumber);

            //assert
            Assert.AreEqual(100m, actual);
        }
Exemple #9
0
        public bool Add(Contract contract, out string strResult)
        {
            strResult = string.Empty;
            bool result = false;
            //var contracts = ContractRepository.GetQueryable().FirstOrDefault(c => c.ContractCode == contract.ContractCode);
            var con = new Contract();

            //if (contracts == null)
            //{
            if (con != null)
            {
                try
                {
                    con.ContractCode     = contract.ContractCode;
                    con.MasterID         = contract.MasterID;
                    con.SupplySideCode   = contract.SupplySideCode;
                    con.DemandSideCode   = contract.DemandSideCode;
                    con.ContractDate     = contract.ContractDate;
                    con.StartDade        = contract.StartDade;
                    con.EndDate          = contract.EndDate;
                    con.SendPlaceCode    = contract.SendPlaceCode;
                    con.SendAddress      = contract.SendAddress;
                    con.ReceivePlaceCode = contract.ReceivePlaceCode;
                    con.ReceiveAddress   = contract.ReceiveAddress;
                    con.SaleDate         = contract.SaleDate;
                    con.State            = contract.State;

                    ContractRepository.Add(con);
                    ContractRepository.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    strResult = "原因:" + ex.Message;
                }
            }
            else
            {
                strResult = "原因:找不到当前登陆用户!请重新登陆!";
            }
            //}
            //else
            //{
            //    strResult = "原因:该编号已存在!";
            //}
            return(result);
        }
Exemple #10
0
        public void ContractRepository_DeleteContractDeliverable_ShouldRemoveDeliverableFromContractAllocation()
        {
            var contract   = GetContract();
            var repository = new ContractRepository();

            repository.Add(contract);

            string cn       = contract.ContractNumber;
            string allocRef = contract.Allocations.First().AllocationReference;
            int    delCode  = contract.Allocations.First().Deliverables.First().Id;

            Assert.IsNotNull(repository.Get(contract.ContractNumber).Allocations.First().Deliverables.First());

            repository.DeleteContractDeliverable(cn, allocRef, delCode);

            Assert.IsNull(repository.Get(cn).Allocations.Single(a => a.AllocationReference == allocRef).Deliverables.SingleOrDefault(d => d.Id == delCode));
        }
Exemple #11
0
        public void ContractRepository_DeleteContractAllocation_ShouldRemoveAllocationFromContract()
        {
            var contract = GetContract();

            var repository = new ContractRepository();

            repository.Add(contract);

            string cn       = contract.ContractNumber;
            string allocRef = contract.Allocations.First().AllocationReference;

            Assert.IsNotNull(repository.Get(contract.ContractNumber).Allocations.First());

            repository.DeleteContractAllocation(contract.ContractNumber, contract.Allocations.First().AllocationReference);

            Assert.IsNull(repository.Get(contract.ContractNumber).Allocations.SingleOrDefault(a => a.AllocationReference == allocRef));
        }
        public void Add(IContract model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model", "");
            }

            if (GetContracts(x => model.Terminal.Id == x.Terminal.Id && x.ContractCloseDate != null).FirstOrDefault() == null)
            {
                using (var repository = new ContractRepository())
                {
                    repository.Add(Mapper.Mapper.DTOtoEntity(model));
                    repository.SaveChanges();
                }
            }
            else
            {
                throw new ArgumentException("Terminal is used in other contract");
            }
        }
Exemple #13
0
        public void ContractService_Add_ShouldAddASingleContract()
        {
            // arrange
            Contract testContract = new Contract
            {
                ContractNumber = "ABC-123",
                Allocations    = new List <ContractAllocation>()
            };

            var repository = new ContractRepository();

            // act
            repository.Add(testContract);

            // assert
            var actual = repository.Get("ABC-123");

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Allocations);
            Assert.IsFalse(actual.Allocations.Any());
            Assert.AreEqual("ABC-123", actual.ContractNumber);
        }
        public void ContractRepositoryTest()
        {
            ContractRepository repository = new ContractRepository();
            Contract expectedContract = new Contract
            {
                agentId = 10,
                builderId = 10,
                clientId = 10,
                projectId = 10
            };

            repository.Add(expectedContract);

            Contract realContract = repository.GetAll().Last();

            Assert.AreEqual(expectedContract, realContract);

            repository.Delete(realContract);

            realContract = repository.GetAll().Last();

            Assert.AreNotEqual(expectedContract, realContract);
        }
Exemple #15
0
        public void ContractService_Add_ShouldAddASingleContractMultipleTimes()
        {
            // arrange
            Contract testContract0 = new Contract
            {
                ContractNumber = "ABC-123",
                Allocations    = new List <ContractAllocation>()
            };

            Contract testContract1 = new Contract
            {
                ContractNumber = "ABC-234",
                Allocations    = new List <ContractAllocation>()
            };

            Contract testContract2 = new Contract
            {
                ContractNumber = "ABC-345",
                Allocations    = new List <ContractAllocation>
                {
                    new ContractAllocation
                    {
                        AllocationReference = "Alloc-1",
                        AllocType           = AllocationType.PayOnActual,
                        Deliverables        = new List <Deliverable>()
                    }
                }
            };

            Contract testContract3 = new Contract
            {
                ContractNumber = "ABC-456",
                Allocations    = new List <ContractAllocation>
                {
                    new ContractAllocation
                    {
                        AllocationReference = "Alloc-1",
                        AllocType           = AllocationType.PayOnProfile,
                        Deliverables        = new List <Deliverable>
                        {
                            new Deliverable
                            {
                                Id    = 1,
                                Value = 0m
                            }
                        }
                    }
                }
            };

            var repository = new ContractRepository();

            // act
            repository.Add(testContract0);
            repository.Add(testContract1);
            repository.Add(testContract2);
            repository.Add(testContract3);

            // assert
            var actual0 = repository.Get("ABC-123");
            var actual1 = repository.Get("ABC-234");
            var actual2 = repository.Get("ABC-345");
            var actual3 = repository.Get("ABC-456");

            Assert.IsNotNull(actual0);
            Assert.IsNotNull(actual0.Allocations);
            Assert.IsFalse(actual0.Allocations.Any());
            Assert.AreEqual("ABC-123", actual0.ContractNumber);

            Assert.IsNotNull(actual1);
            Assert.IsNotNull(actual1.Allocations);
            Assert.IsFalse(actual1.Allocations.Any());
            Assert.AreEqual("ABC-234", actual1.ContractNumber);

            Assert.IsNotNull(actual2);
            Assert.IsNotNull(actual2.Allocations);
            Assert.IsTrue(actual2.Allocations.Any());
            Assert.AreEqual("ABC-345", actual2.ContractNumber);

            Assert.IsNotNull(actual3);
            Assert.IsNotNull(actual3.Allocations);
            Assert.IsTrue(actual3.Allocations.Any());
            Assert.AreEqual("ABC-456", actual0.ContractNumber);
        }
        public NewContractViewModel()
        {
            var      now             = DateTime.Now;
            DateTime defaultFromDate = new DateTime(now.Year, 1, 1);
            DateTime defaultToDate   = new DateTime(now.Year, 12, 31);

            _inputFromDate = defaultFromDate;
            _inputToDate   = defaultToDate;

            _errorsList.Clear();
            ContractRepository contractRepository = new ContractRepository();

            AddCommand = new RelayCommand <object>((p) =>
            {
                if (string.IsNullOrEmpty(this.InputId))
                {
                    return(false);
                }

                if (this.InputFromDate == null)
                {
                    return(false);
                }

                if (this.InputToDate == null)
                {
                    return(false);
                }

                if (this.InputId.Length > 50)
                {
                    UpdateResultAsync(Result.HasError, "Độ dài tối đa của số Hợp đồng là 50 ký tự");
                }
                else
                {
                    UpdateResultAsync(Result.ExcludeError, "Độ dài tối đa của số Hợp đồng là 50 ký tự");
                }

                if (this.InputFromDate > this.InputToDate)
                {
                    UpdateResultAsync(Result.HasError, "Ngày bắt đầu hiệu lực phải trước ngày kết thúc");
                }
                else
                {
                    UpdateResultAsync(Result.ExcludeError, "Ngày bắt đầu hiệu lực phải trước ngày kết thúc");
                }

                if (this.InputAnnualPremiumPerInsured == 0)
                {
                    UpdateResultAsync(Result.HasError, "Phí bảo hiểm phải lớn hơn 0");
                }
                else
                {
                    UpdateResultAsync(Result.ExcludeError, "Phí bảo hiểm phải lớn hơn 0");
                }

                var creatingContract = contractRepository.GetContract(InputId);
                if (creatingContract != null)
                {
                    UpdateResultAsync(Result.HasError, "Số Hợp đồng này đã tồn tại");
                }
                else
                {
                    UpdateResultAsync(Result.ExcludeError, "Số Hợp đồng này đã tồn tại");
                }


                if (_errorsList.Count > 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }, (p) =>
            {
                Contract newContract = new Contract();
                newContract.Id       = this.InputId.Trim(' ').ToUpper();
                newContract.FromDate = (DateTime)this.InputFromDate;
                newContract.ToDate   = (DateTime)this.InputToDate;
                newContract.AnnualPremiumPerInsured = this.InputAnnualPremiumPerInsured;

                contractRepository.Add(newContract);
                contractRepository.Save();

                Success = "Đã tạo hợp đồng";
                UpdateResultAsync(Result.Successful);

                InputId       = null;
                InputFromDate = defaultFromDate;
                InputToDate   = defaultToDate;
                InputAnnualPremiumPerInsured = 0;

                IsStartOver = true;
                OnPropertyChanged("IsStartOver");
                IsStartOver = false;
            });
        }