public Contract DeleteTheLastTimeline(int contractID)
 {
     ContractRepository contractRepo = new ContractRepository() { DB = DB };
     var r = contractRepo.Get(contractID);
     var lastTimeline = r.ContractTimelines.OrderByDescending(r1 => r1.Order).FirstOrDefault();
     if (lastTimeline != null)
     {
         DB.DeleteObject(lastTimeline);
         Save();
     }
     return r;
 }
        public Contract DeleteTheLastTimeline(int contractID)
        {
            ContractRepository contractRepo = new ContractRepository()
            {
                DB = DB
            };
            var r            = contractRepo.Get(contractID);
            var lastTimeline = r.ContractTimelines.OrderByDescending(r1 => r1.Order).FirstOrDefault();

            if (lastTimeline != null)
            {
                DB.DeleteObject(lastTimeline);
                Save();
            }
            return(r);
        }
        public ContractTimeline Add(int contractID, int timeCount, string timeUnit)
        {
            timeCount = timeCount < 1 ? 1 : timeCount;
            ContractRepository contractRepo = new ContractRepository()
            {
                DB = DB
            };
            Contract contract = contractRepo.Get(contractID);

            ContractTimeline lastContractTimeline = contract.ContractTimelines.OrderByDescending(r => r.Order).FirstOrDefault();

            ContractTimeline newContractTimeline = new ContractTimeline();

            if (lastContractTimeline == null)
            {
                newContractTimeline.Order    = 1;
                newContractTimeline.FromDate = contract.SignedDate.HasValue ? contract.SignedDate : DateTime.Now.Date;
            }
            else
            {
                newContractTimeline.Order    = lastContractTimeline.Order + 1;
                newContractTimeline.FromDate = lastContractTimeline.ToDate.Value.AddDays(1);
            }

            if (timeUnit.ToLower() == "day")
            {
                newContractTimeline.ToDate = newContractTimeline.FromDate.Value.AddDays(timeCount).AddDays(-1);
            }
            else if (timeUnit.ToLower() == "month")
            {
                newContractTimeline.ToDate = newContractTimeline.FromDate.Value.AddMonths(timeCount).AddDays(-1);
            }

            newContractTimeline.ContractID = contractID;

            DB.AddToContractTimelines(newContractTimeline);

            Save();

            return(newContractTimeline);
        }
        public ContractTimeline Add(int contractID, int timeCount, string timeUnit)
        {
            timeCount = timeCount < 1 ? 1 : timeCount;
            ContractRepository contractRepo = new ContractRepository() { DB = DB };
            Contract contract = contractRepo.Get(contractID);

            ContractTimeline lastContractTimeline = contract.ContractTimelines.OrderByDescending(r => r.Order).FirstOrDefault();

            ContractTimeline newContractTimeline = new ContractTimeline();

            if (lastContractTimeline == null)
            {
                newContractTimeline.Order = 1;
                newContractTimeline.FromDate = contract.SignedDate.HasValue ? contract.SignedDate : DateTime.Now.Date;
            }
            else
            {
                newContractTimeline.Order = lastContractTimeline.Order + 1;
                newContractTimeline.FromDate = lastContractTimeline.ToDate.Value.AddDays(1);
            }

            if (timeUnit.ToLower() == "day")
            {
                newContractTimeline.ToDate = newContractTimeline.FromDate.Value.AddDays(timeCount).AddDays(-1);
            }
            else if (timeUnit.ToLower() == "month")
            {
                newContractTimeline.ToDate = newContractTimeline.FromDate.Value.AddMonths(timeCount).AddDays(-1);
            }

            newContractTimeline.ContractID = contractID;

            DB.AddToContractTimelines(newContractTimeline);

            Save();

            return newContractTimeline;
        }