Beispiel #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;
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public static List <UserDTO> GetUsersList(int id)
 {
     if (db.Users.FirstOrDefault(x => x.id == id).isManager)
     {
         return(Convertions.Convertion(db.Users.Where(y => !y.isManager || y.id == id).ToList()));
     }
     return(null);
 }
Beispiel #3
0
        public static UserDTO IfExsistRavKav(string ravKav, string pass)
        {
            User user = db.Users.ToList().FirstOrDefault(x => x.ravkavNum == ravKav && x.pass == pass);

            if (user != null)
            {
                return(Convertions.Convertion(user));
            }

            return(null);
        }
Beispiel #4
0
        public static List <TravelsDTO> getTravels(int id)
        {
            int               month     = 01;
            int               year      = 2021;
            List <Travel>     travel    = db.Travels.Where(l => l.userID == id && l.date.Month == month && l.date.Year == year).ToList();
            List <TravelsDTO> travelDTO = new List <TravelsDTO>();

            foreach (var item in travel)
            {
                travelDTO.Add(Convertions.Convertion(item));
            }
            return(travelDTO);
        }
Beispiel #5
0
        public static bool UpdateUser(UserDTO user)
        {
            User u = Convertions.Convertion(user);

            try
            {
                db.Users.Attach(u);
                db.Entry <User>(u).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #6
0
        public static bool AddUser(UserDTO user)
        {
            db.sp_addUder_Insert(user.fName, user.lName, user.email, user.pass, user.ravkav, user.profileId);

            User u = Convertions.Convertion(user);

            try
            {
                db.Users.Add(u);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #7
0
 public static UserDTO UserDetails(int id)
 {
     return(Convertions.Convertion(db.Users.FirstOrDefault(x => x.id == id)));
 }
Beispiel #8
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);
                    }
                }
            }
        }
Beispiel #9
0
        //find base contract
        //the rules of base contract are:
        //contract who as the area of current travel
        //and this contract is cheapest cheapest
        public static void ContractBase(int id)
        {
            //contractUsed = new Dictionary<ContractInformation, List<Area>>();
            int contractTemp = -1;
            //Dictionary of used travels
            var    profile         = db.Profiles.Where(b => b.Users.Any(c => c.id == id)).FirstOrDefault();
            double profileDiscount = 0;

            if (profile != null)
            {
                profileDiscount = Convert.ToDouble(profile.discount);
            }
            double         price = 0;
            List <Travel>  travelsToCurrentContract;
            AreaToContract areaToCurrentContract;

            //Go over the travel list for the user
            for (int i = 0; i < travelsByDate.Count; i++)
            {
                if (travelUsed.ContainsKey(travelsByDate[i]))
                {
                    continue;
                }
                price = 0;
                //Finding the right and cheapest contract

                areaToCurrentContract = travelsByDate[i].Area.AreaToContracts.
                                        OrderBy(x => (type == "freeDay" ? x.Contract.freeDay : x.Contract.freeMounth)).FirstOrDefault();

                if (areaToCurrentContract != null)
                {
                    currentContract = areaToCurrentContract.Contract;
                }
                if (currentContract.id == contractTemp)
                {
                    continue;
                }
                contractTemp = currentContract.id;
                //Pulling out all travel appropriate to the contract
                travelsToCurrentContract = travelsByDate.Where(x => x.Area.AreaToContracts.Any(m => m.contractID == currentContract.id)).ToList();
                foreach (var item in travelsToCurrentContract)
                {
                    //Check if some of the travels have already been realized in other contracts, if not sum them price
                    if (!travelUsed.ContainsKey(item))
                    {
                        price += item.price;
                    }
                }
                if ((type == "freeDay" ? currentContract.freeDay : currentContract.freeMounth) <= price * profileDiscount)

                {
                    areaToCurrentContractTemp   = new List <Area>();
                    travelsToCurrentContractDTO = new List <TravelsDTO>();
                    //Add the travels to the travelUsed that for them a contract has been found
                    foreach (var item in travelsToCurrentContract)
                    {
                        if (!travelUsed.ContainsKey(item))
                        {
                            areaToCurrentContractTemp.Add(item.Area);
                            travelUsed.Add(item, currentContract.id);
                            travelsToCurrentContractDTO.Add(Convertions.Convertion(item));
                        }
                    }
                    //add the current contract to dictionary contractUsed
                    contractUsed.Add(new ContractInformation(currentContract.id,
                                                             (type == "freeDay" ? currentContract.freeDay : currentContract.freeMounth), true, travelsToCurrentContractDTO), areaToCurrentContractTemp);
                }
            }

            //add signal travels to contract used dictionary
            foreach (var travel in travelsByDate)
            {
                if (!travelUsed.ContainsKey(travel))
                {
                    List <Area> listSignalArea = new List <Area>();
                    listSignalArea.Add(travel.Area);
                    contractUsed.Add(new ContractInformation(travel.id, travel.price, false), listSignalArea);
                }
            }
        }