Пример #1
0
        public ActionResult Index()
        {
            if (User.IsInRole("Admin"))
            {
                var myStations = db.Stations.ToList();

                var indexCompanyDTO = new IndexCompanyDTO();
                indexCompanyDTO.myStations = myStations;

                return(View("../Home/IndexCompany", indexCompanyDTO));
            }

            var StationDTO = new StationDTO(db.Stations.Where(e => e.Status == "Accepted" || e.Status == "accepted").ToList());

            return(View(StationDTO));
        }
        public ActionResult Index()
        {
            if (Request.IsAuthenticated)
            {
                if (User.IsInRole("Client"))
                {
                    var client         = GetClient();
                    var indexClientDTO = new IndexClientDTO();

                    db.Reservations
                    .Join(db.ChargingPoints,
                          reser => reser.ChargingPoint,
                          charg => charg,
                          (reser, charg) => new
                    {
                        Reser = reser,
                        Charg = charg
                    }
                          )
                    .Join(db.Stations,
                          joined => joined.Charg.Station,
                          stat => stat,
                          (joined, stat) => new
                    {
                        Joined = joined,
                        Stat   = stat
                    }
                          )
                    .OrderByDescending(e => e.Joined.Reser.Date)
                    .Where(e => e.Joined.Reser.Client.Id == client.Id)
                    .Where(e => e.Joined.Reser.Status == ConstantValues.READY)
                    .Select(e => new
                    {
                        Reservation = e.Joined.Reser,
                        StationName = e.Stat.Name
                    }).Take(5).ToList().ForEach(e => indexClientDTO.myReservations.Add(new ReservationDetailsViewModel(e.Reservation, e.StationName)));

                    db.Reservations
                    .Join(db.ChargingPoints,
                          reser => reser.ChargingPoint,
                          charg => charg,
                          (reser, charg) => new
                    {
                        Reser = reser,
                        Charg = charg
                    }
                          )
                    .Join(db.Stations,
                          joined => joined.Charg.Station,
                          stat => stat,
                          (joined, stat) => new
                    {
                        Joined = joined,
                        Stat   = stat
                    }
                          )
                    .OrderByDescending(e => e.Joined.Reser.Date)
                    .Where(e => e.Joined.Reser.Client.Id == client.Id)
                    .Where(e => e.Joined.Reser.Status == ConstantValues.DONE)
                    .Select(e => new
                    {
                        Reservation = e.Joined.Reser,
                        StationName = e.Stat.Name
                    }).Take(5).ToList().ForEach(e => indexClientDTO.reservationsHistory.Add(new ReservationDetailsViewModel(e.Reservation, e.StationName)));


                    return(View("IndexClient", indexClientDTO));
                }
                else if (User.IsInRole("Company"))
                {
                    var company = GetCompany();

                    if (company.Status == ConstantValues.ACCEPTED)
                    {
                        var myStations       = db.Stations.Where(e => e.Companies.Id == company.Id).ToList();
                        var myChargingPoints = db.ChargingPoints.Where(e => e.Station.Companies.Id == company.Id).ToList();

                        var indexCompanyDTO = new IndexCompanyDTO();
                        indexCompanyDTO.myStations       = myStations;
                        indexCompanyDTO.myChargingPoints = myChargingPoints;

                        return(View("IndexCompany", indexCompanyDTO));
                    }
                    else
                    {
                        return(View("PendingApproval"));
                    }
                }
            }


            return(View());
        }