コード例 #1
0
        public IHttpActionResult PutUserMaster(AirlineDetail airline)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                AirlineDetail objUsr = new AirlineDetail();
                objUsr = objEntity.AirlineDetails.Find(airline.Id);
                if (objUsr != null)
                {
                    objUsr.Id          = airline.Id;
                    objUsr.Name        = airline.Name;
                    objUsr.Address     = airline.Address;
                    objUsr.Description = airline.Description;
                }
                int i = objEntity.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
            return(Ok(airline));
        }
コード例 #2
0
        public IHttpActionResult AddAirlineAdmin(int airlineId, string adminName)
        {
            AirlineDetail airline = objEntity.AirlineDetails.Find(airlineId);
            UserDetail    user    = objEntity.UserDetails.Find(adminName);

            airline.AdminId = user.UserId;
            objEntity.SaveChanges();
            return(Ok(airline));
        }
コード例 #3
0
        public IHttpActionResult DeleteUserDelete(int id)
        {
            //int empId = Convert.ToInt32(id);
            AirlineDetail airline = objEntity.AirlineDetails.Find(id);

            if (airline == null)
            {
                return(NotFound());
            }

            objEntity.AirlineDetails.Remove(airline);
            objEntity.SaveChanges();

            return(Ok(airline));
        }
コード例 #4
0
        public IHttpActionResult GetAirlineByAdminId(string adminId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            AirlineDetail airline = new AirlineDetail();

            try
            {
                int id = Convert.ToInt32(adminId);
                airline = objEntity.AirlineDetails.Where(a => a.AdminId == id).FirstOrDefault();
            }
            catch (Exception e)
            {
            }
            return(Ok(airline));
        }
コード例 #5
0
        public IHttpActionResult PostUser(AirlineDetail data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                objEntity.AirlineDetails.Add(data);
                objEntity.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }

            return(Ok(data));
        }
コード例 #6
0
        public IHttpActionResult GetAirlineById(string airlineId)
        {
            AirlineDetail objUsr = new AirlineDetail();
            int           ID     = Convert.ToInt32(airlineId);

            try
            {
                objUsr = objEntity.AirlineDetails.Find(ID);
                if (objUsr == null)
                {
                    return(NotFound());
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(Ok(objUsr));
        }
コード例 #7
0
        public IHttpActionResult PostAirlineRate(string rate, string userId, string airlineId)
        {
            AirlineRate airlineRate = new AirlineRate();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                airlineRate.Rate      = Convert.ToInt32(rate);
                airlineRate.AirlineId = Convert.ToInt32(airlineId);
                airlineRate.UserId    = Convert.ToInt32(userId);
                airlineRate.RateDate  = DateTime.Now;

                objEntity.AirlineRates.Add(airlineRate);
                objEntity.SaveChanges();
                var           rateAirlineId = Convert.ToInt32(airlineId);
                AirlineDetail airline       = objEntity.AirlineDetails.Find(airlineRate.AirlineId);
                var           listRates     = objEntity.AirlineRates.Where(a => a.AirlineId == rateAirlineId).ToList();
                double        sum           = 0;
                foreach (var r in listRates)
                {
                    sum += r.Rate;
                }
                //double sum = airline.Rate * airline.RatedBy + rentaCarRate.Rate;
                //rentaCar.RatedBy++;
                airline.Rate = Math.Round((sum / listRates.Count), 2);


                objEntity.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }

            return(Ok(airlineRate));
        }
コード例 #8
0
        public List <string> RatesReport(string airlineAdminId, string period)
        {
            var           adminId   = Convert.ToInt32(airlineAdminId);
            AirlineDetail airline   = objEntity.AirlineDetails.Where(ad => ad.AdminId == adminId).FirstOrDefault();
            List <int>    flightIds = new List <int>();

            foreach (Flight flight in objEntity.Flights.Where(c => c.IdAvioKompanije == airline.Id))
            {
                flightIds.Add(flight.Id);
            }


            List <string> reports = new List <string>();

            IQueryable <FlightRate> flightRates = objEntity.FlightRates.Where(flyRate => flightIds.Contains(flyRate.FlightId));

            IQueryable <AirlineRate> airlineRates = objEntity.AirlineRates.Where(airRate => airRate.AirlineId == airline.Id);
            IQueryable <Flight>      flights      = objEntity.Flights.Where(flight => flight.IdAvioKompanije == airline.Id);


            DateTime yesterday = DateTime.Today.AddDays(-1);
            DateTime weekAgo   = DateTime.Today.AddDays(-7);
            DateTime monthAgo  = DateTime.Today.AddMonths(-1);
            DateTime yearAgo   = DateTime.Today.AddYears(-1);

            switch (period)
            {
            case "day":
            {
                flightRates  = flightRates.Where(cr => cr.RateDate >= yesterday);
                airlineRates = airlineRates.Where(rcr => rcr.RateDate >= yesterday);
            }
            break;

            case "week":
            {
                flightRates  = flightRates.Where(cr => cr.RateDate >= weekAgo);
                airlineRates = airlineRates.Where(rcr => rcr.RateDate >= weekAgo);
            }
            break;

            case "month":
            {
                flightRates  = flightRates.Where(cr => cr.RateDate >= monthAgo);
                airlineRates = airlineRates.Where(rcr => rcr.RateDate >= monthAgo);
            }
            break;

            case "year":
            {
                flightRates  = flightRates.Where(cr => cr.RateDate >= yearAgo);
                airlineRates = airlineRates.Where(rcr => rcr.RateDate >= yearAgo);
            }
            break;

            default:
                break;
            }

            reports.Add(" ");
            reports.Add("Airline company rates: ");
            reports.Add(" ");
            reports.Add(" ");
            foreach (AirlineRate rcr in airlineRates)
            {
                if (rcr.Rate != 0)
                {
                    var user = objEntity.UserDetails.Find(rcr.UserId);
                    reports.Add("User: "******" " + user.LastName + " rated with " + rcr.Rate + " on " + rcr.RateDate.ToShortDateString() + ".");
                    reports.Add(" ");
                }
            }

            reports.Add("Average rate of this airline company is " + airline.Rate);

            reports.Add(" ");
            reports.Add(" ");

            reports.Add("Flight rates: ");
            reports.Add(" ");
            reports.Add(" ");

            foreach (FlightRate cr in flightRates)
            {
                if (cr.Rate != 0)
                {
                    var user = objEntity.UserDetails.Find(cr.UserId);
                    reports.Add("User: "******" " + user.LastName + " rated flight " + cr.FlightId + " with " + cr.Rate + " on " + cr.RateDate.ToShortDateString() + ".");
                    reports.Add(" ");
                }
            }


            reports.Add(" ");
            reports.Add(" ");

            foreach (Flight c in flights)
            {
                if (c.Rate != null)
                {
                    reports.Add("Average rate of flight " + c.Id + " is " + c.Rate);
                    reports.Add(" ");
                }
            }

            reports.Add(" ");
            reports.Add(" ");

            return(reports);
        }