コード例 #1
0
ファイル: RideRepository.cs プロジェクト: KianTM/RideService
        public List <Ride> HandleData(DataTable dataTable)
        {
            ReportRepository    reportRepository = new ReportRepository();
            CategoryRepository  catRepo          = new CategoryRepository();
            List <RideCategory> categories       = catRepo.GetAllCategories();
            List <Ride>         rides            = new List <Ride>();

            foreach (DataRow row in dataTable.Rows)
            {
                int    id             = (int)row["RideId"];
                string name           = (string)row["Name"];
                string description    = (string)row["Description"];
                int    rideCategoryId = (int)row["RideCategoryId"];

                RideCategory rideCategory = null;
                foreach (RideCategory category in categories)
                {
                    if (category.Id == rideCategoryId)
                    {
                        rideCategory = category;
                        break;
                    }
                }
                Ride ride = new Ride(id, name, description, rideCategory);
                reportRepository.SetAllReportsForRide(ride);
                rides.Add(ride);
            }

            return(rides);
        }
コード例 #2
0
        private List <RideCategory> HandleData(DataTable dataTable)
        {
            List <RideCategory> categories = new List <RideCategory>();

            foreach (DataRow row in dataTable.Rows)
            {
                RideCategory category = new RideCategory((int)row["RideCategoryId"], (string)row["Name"], (string)row["Description"]);
                categories.Add(category);
            }
            return(categories);
        }
コード例 #3
0
        public RideCategory GetMostBrokenCategory(List <Ride> ridesList = null)
        {
            CategoryRepository  categoryRepository = new CategoryRepository();
            RideRepository      rideRepository     = new RideRepository();
            ReportRepository    reportRepository   = new ReportRepository();
            List <RideCategory> categories         = categoryRepository.GetRideCategories();
            RideCategory        categoryToReturn   = null;
            int         breakdowns = 0;
            List <Ride> rides      = ridesList;

            foreach (RideCategory category in categories)
            {
                if (categoryToReturn is null)
                {
                    categoryToReturn = category;
                    if (rides is null)
                    {
                        breakdowns = reportRepository.TotalBreakdowns(rideRepository.GetMostBrokenRide(category.Id).Id);
                    }
                    else
                    {
                        breakdowns = reportRepository.TotalBreakdowns(rideRepository.GetMostBrokenRide(category.Id, rides).Id, rides);
                    }
                }
                else
                {
                    int categoryBreakdowns = 0;
                    if (rides is null)
                    {
                        Ride mostBrokenRide = rideRepository.GetMostBrokenRide(category.Id);
                        if (mostBrokenRide != null)
                        {
                            categoryBreakdowns = reportRepository.TotalBreakdowns(mostBrokenRide.Id);
                        }
                    }
                    else
                    {
                        Ride mostBrokenRide = rideRepository.GetMostBrokenRide(category.Id, rides);
                        if (mostBrokenRide != null)
                        {
                            categoryBreakdowns = reportRepository.TotalBreakdowns(mostBrokenRide.Id, rides);
                        }
                    }

                    if (categoryBreakdowns > breakdowns)
                    {
                        categoryToReturn = category;
                        breakdowns       = categoryBreakdowns;
                    }
                }
            }

            return(categoryToReturn);
        }
コード例 #4
0
 public int InsertRideCategory(RideCategory r)
 {
     if (GetRideCategories().Find(c => c.Name == r.Name) != null)
     {
         return(-1);
     }
     if (!string.IsNullOrEmpty(r.Description) && !string.IsNullOrEmpty(r.Name))
     {
         return(ExecuteNonQuery($"Insert into RideCategories(Name, Description) values('{r.Name}','{r.Description}')"));
     }
     return(0);
 }
コード例 #5
0
ファイル: index.cshtml.cs プロジェクト: JosaAspit/RideService
        public void OnGet()
        {
            CategoryRepository categoryRepository = new CategoryRepository();
            ReportRepository   reportRepository   = new ReportRepository();
            RideRepository     rideRepository     = new RideRepository();

            List <Ride> rides = rideRepository.GetRides();

            MostBrokenRide         = rideRepository.GetMostBrokenRide(null, rides);
            LastBrokenRide         = rideRepository.GetLastBrokenRide(rides);
            LeastBrokenRide        = rideRepository.GetLeastBrokenRide(rides);
            DaysSinceLastBreakdown = reportRepository.DaysSinceLastBreakdownOnRides(rides);
            MostBrokenCategory     = categoryRepository.GetMostBrokenCategory(rides);
        }
コード例 #6
0
        public List <RideCategory> HandleData(DataTable dataTable)
        {
            List <RideCategory> categories = new List <RideCategory>();

            foreach (DataRow row in dataTable.Rows)
            {
                int    id          = (int)row["RideCategoryId"];
                string name        = (string)row["Name"];
                string description = (string)row["Description"];

                RideCategory category = new RideCategory(id, name, description);
                categories.Add(category);
            }

            return(categories);
        }
コード例 #7
0
        public RideCategory GetRideCategory(int id)
        {
            string  sql = $"SELECT * FROM RideCategories WHERE RideCategoryId = {id}";
            DataSet ds  = ExecuteQuery(sql);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                RideCategory rideCategory = new RideCategory(
                    (string)row["Description"],
                    (string)row["Name"],
                    (int)row["RideCategoryId"]
                    );

                return(rideCategory);
            }

            return(null);
        }
コード例 #8
0
        public void OnPost()
        {
            CategoryRepository categoryRepo = new CategoryRepository();

            Categories = categoryRepo.GetAllRideCategories();

            if (!string.IsNullOrWhiteSpace(CategoryName))
            {
                if (!string.IsNullOrWhiteSpace(CategoryDescription))
                {
                    RideCategory newCategory = new RideCategory
                    {
                        Name        = CategoryName,
                        Description = CategoryDescription
                    };

                    foreach (RideCategory rideCategory in Categories)
                    {
                        if (rideCategory.Name == newCategory.Name)
                        {
                            NameUsed = true;
                        }
                    }

                    if (!NameUsed)
                    {
                        categoryRepo.AddCategory(newCategory);
                        Message = "Kategori oprettet";
                    }
                    else
                    {
                        Message = "Kategorinavnet er allerede i brug, og blev derfor ikke oprettet";
                    }
                }
                else
                {
                    Message = "Beskrivelsen skal have en værdi";
                }
            }
            else
            {
                Message = "Navn skal have en værdi";
            }
        }
コード例 #9
0
        public List <RideCategory> GetRideCategories()
        {
            string              sql = $"SELECT * FROM RideCategories";
            DataSet             ds  = ExecuteQuery(sql);
            List <RideCategory> rcl = new List <RideCategory>();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                RideCategory rideCategory = new RideCategory(
                    (string)row["Description"],
                    (string)row["Name"],
                    (int)row["RideCategoryId"]
                    );

                rcl.Add(rideCategory);
            }

            return(rcl);
        }
コード例 #10
0
        public List <RideCategory> GetAllRideCategories()
        {
            List <RideCategory> categories      = new List <RideCategory>();
            DataTable           categoriesTable = ExecuteQuery("SELECT * FROM RideCategories");

            foreach (DataRow row in categoriesTable.Rows)
            {
                int          id          = (int)row["RideCategoryId"];
                string       name        = (string)row["Name"];
                string       description = (string)row["Description"];
                RideCategory category    = new RideCategory()
                {
                    Id          = id,
                    Name        = name,
                    Description = description
                };
                categories.Add(category);
            }
            return(categories);
        }
コード例 #11
0
        public void AddCategory(RideCategory category)
        {
            string sqlInsert = $"INSERT INTO RideCategories VALUES('{category.Name}','{category.Description}')";

            ExecuteNonQuery(sqlInsert);
        }
コード例 #12
0
        public List <Ride> GetRides()
        {
            CategoryRepository categoryRepository = new CategoryRepository();
            ReportRepository   reportRepository   = new ReportRepository();

            List <Ride> rides = new List <Ride>();
            string      sql   = "SELECT Rides.RideId, Rides.Name, Rides.Description, Rides.CategoryId, Rides.Status, Reports.Status AS ReportStatus, Reports.ReportTime, Reports.Notes, Reports.RideId AS ReportRideId FROM Rides LEFT JOIN Reports ON Rides.RideId = Reports.RideId";

            DataSet ds = ExecuteQuery(sql);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                RideCategory rideCategory = categoryRepository.GetRideCategory((int)row["CategoryId"]);

                bool rideExists = false;

                if (rides.Count == 0)
                {
                    Ride ride = new Ride(
                        (Status)(int)row["Status"],
                        rideCategory,
                        (string)row["Description"],
                        (string)row["Name"],
                        (int)row["RideId"]
                        );

                    if (int.TryParse(row["ReportStatus"].ToString(), out int status))
                    {
                        Report report = new Report(
                            (string)row["Notes"],
                            (DateTime)row["ReportTime"],
                            (Status)(int)row["ReportStatus"],
                            ride,
                            (int)row["ReportRideId"]
                            );

                        ride.Reports.Add(report);
                    }

                    rides.Add(ride);
                }
                else
                {
                    foreach (Ride ride in rides)
                    {
                        if (ride.Id == (int)row["RideId"])
                        {
                            if (int.TryParse(row["ReportStatus"].ToString(), out int status))
                            {
                                Report report = new Report(
                                    (string)row["Notes"],
                                    (DateTime)row["ReportTime"],
                                    (Status)(int)row["ReportStatus"],
                                    ride,
                                    (int)row["ReportRideId"]
                                    );

                                ride.Reports.Add(report);
                            }

                            rideExists = true;
                        }
                    }

                    if (!rideExists)
                    {
                        Ride ride = new Ride(
                            (Status)(int)row["Status"],
                            rideCategory,
                            (string)row["Description"],
                            (string)row["Name"],
                            (int)row["RideId"]
                            );

                        if (int.TryParse(row["ReportStatus"].ToString(), out int status))
                        {
                            Report report = new Report(
                                (string)row["Notes"],
                                (DateTime)row["ReportTime"],
                                (Status)(int)row["ReportStatus"],
                                ride,
                                (int)row["ReportRideId"]
                                );

                            ride.Reports.Add(report);
                        }

                        rides.Add(ride);
                    }
                }
            }

            return(rides);
        }
コード例 #13
0
        public void AddCategoryToDB(RideCategory rideCategory)
        {
            string sql = $"INSERT INTO RideCategories VALUES('{rideCategory.Name}', '{rideCategory.Description}')";

            ExecuteNonQuery(sql);
        }