Ejemplo n.º 1
0
        public static void addToCalculateResulte()
        {
            Contract con3;

            foreach (var item in contractUsed)
            {
                if (item.Key.isContract == true)
                {
                    con3 = contracts.Where(u => u.id == item.Key.idContractOrTravel).FirstOrDefault();
                    if (con3 != null)
                    {
                        CalculateResulte c = new CalculateResulte(travelsToCurrentContractDTO, type == "freeDay" ? true : false, con3.Description, item.Key.idContractOrTravel, item.Key.price);
                        if (!calculateResultes.Contains(c))
                        {
                            calculateResultes.Add(c);
                        }
                    }
                }
                else
                {
                    if (type == "freeDay")
                    {
                        Travel tr = db.Travels.Where(q => q.id == item.Key.idContractOrTravel).FirstOrDefault();
                        if (tr != null)
                        {
                            TravelsDTO trDTO = Convertions.Convertion(tr);
                            calculateResultes[0].TravelToCon.Add(trDTO);
                            calculateResultes[0].price += item.Key.price;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void ContractExtention(int id)
        {
            Area areaToList = new Area();

            areaToCurrentContractTemp = new List <Area>();
            bool b = func(id);

            while (b)
            {
                ContractInformation con;

                for (int i = 0; i < contractUsed.Count(); i++)
                // foreach (var c in contractUsed)
                {
                    if (contracts.Select(x => x.AreaToContracts.Join(contractUsed.ElementAt(i).Value, AreaToCon => AreaToCon.areaID, itemArea => itemArea.id, (AreaToCon, itemArea) => new { AreaToCon, itemArea }).Where(y => y.AreaToCon.contractID == conid)).Any())
                    {//create list of areas thet include in the extation contract
                        for (int v = 0; v < contractUsed.ElementAt(i).Value.Count(); v++)
                        //  foreach (var area in contractUsed.ElementAt(i).Value)
                        {
                            areaToList = contractUsed.ElementAt(i).Value[v];
                            if (areaToList != null)
                            {
                                areaToCurrentContractTemp.Add(areaToList);
                            }
                        }
                        //adding a single travel that included in the extantion contract to travelUsed
                        if (contractUsed.ElementAt(i).Key.isContract == false)
                        {
                            var g = travelsById.Where(x => x.id == contractUsed.ElementAt(i).Key.idContractOrTravel).FirstOrDefault();
                            if (g != null)
                            {
                                g.fContractID    = conid;
                                g.contractType   = type == "freeDay" ? true : false;
                                g.fFinalAmountID = finalAmount.id;
                                travelUsed.Add(g, conid);
                            }

                            //remove contracts and single travels that in the the extantion contract
                            contractUsed.Remove(contractUsed.ElementAt(i));
                        }
                    }
                    for (int j = 0; j < travelUsed.Count(); j++)
                    //foreach (var t in travelUsed)
                    { //changing the contract code for travels that were included in the contract that extaned
                        ContractInformation a = null;
                        Contract            g = new Contract();
                        if (travelUsed.ElementAt(j).Value == 0)
                        {
                            g = db.Contracts.Where(y => y.code == 0).FirstOrDefault();
                            if (g != null)
                            {
                                a = new ContractInformation(travelUsed.ElementAt(j).Value, (type == "freeDay" ? g.freeDay : g.freeMounth), true);
                            }
                        }
                        else
                        {
                            g = contracts.Where(m => m.id == travelUsed.ElementAt(j).Value).FirstOrDefault();
                            if (g != null)
                            {
                                a = new ContractInformation(travelUsed.ElementAt(j).Value, (type == "freeDay" ? g.freeDay : g.freeMounth), true);
                            }
                        }
                        if (!contractUsed.ContainsKey(a))
                        {
                            travelUsed[travelUsed.ElementAt(j).Key] = conid;
                        }
                        travelsToCurrentContractDTO.Add(Convertions.Convertion(travelUsed.ElementAt(j).Key));
                    }
                    //add extation contract to contractUsed
                    con = new ContractInformation(conid, (type == "freeDay" ? extntionContract.freeDay : extntionContract.freeMounth), true, travelsToCurrentContractDTO);
                    contractUsed.Add(con, areaToCurrentContractTemp);
                    b = func(id);
                }
                string day = travelsByDate[0].date.Day.ToString();
                //create a travel list for each contract
                foreach (var contract in contractUsed)
                {
                    if (contract.Key.isContract == false)
                    {
                        continue;
                    }
                    List <TravelsDTO> t = new List <TravelsDTO>();
                    if (type == "freeMounth")
                    {
                        foreach (var travel in travelUsed)
                        {
                            if (travel.Value == contract.Key.id)
                            {
                                t.Add(Convertions.Convertion(travel.Key));
                            }
                        }
                    }
                    else
                    {
                        foreach (var travel in travelUsed)
                        {
                            if (travel.Value == contract.Key.id && travel.Key.date.Day.ToString() == day)
                            {
                                t.Add(Convertions.Convertion(travel.Key));
                            }
                        }
                    }
                    CalculateResulte conresult;
                    var d = contracts.Where(x => x.id == contract.Key.id).FirstOrDefault().Description;
                    if (d != null)
                    {
                        conresult = new CalculateResulte(t, type == "freeDay" ? true : false, d, contract.Key.id, contract.Key.price);
                        calculateResultes.Add(conresult);
                    }
                }
            }
        }