public ActionResult Index() { UsersInserted ui = new UsersInserted(); ui.users = null; return(View(ui)); }
public ActionResult ChosenSport(string sport) { var specAthletes = _repository.GetSpecificAthletes(sport); UsersInserted users = new UsersInserted(); users.users = specAthletes.Select(x => new UserTable { id = x.id, firstName = x.firstName, lastName = x.lastName, badgeNumber = x.badgeNumber, nationality = x.nationality }).ToList(); ViewBag.sport = sport; return(View("AddCompetitionDetails", users)); }
public ActionResult GetAllUsers() { var listOfUsers = _repository.GetAllUsers(); UsersInserted ui = new UsersInserted(); ui.users = listOfUsers.Select(x => new UserTable { id = x.id, firstName = x.firstName, lastName = x.lastName, role = x.role }).ToList(); return(View("AllUsers", ui)); }
public ActionResult UploadFile(HttpPostedFileBase txtFile) { string fileName = Path.GetFileNameWithoutExtension(txtFile.FileName); string extension = Path.GetExtension(txtFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; string filePath = @"C:\Users\Muhammed\source\repos\ReadJsonOlympicGames\ReadJsonOlympicGames\Files\" + fileName; fileName = Path.Combine(Server.MapPath("~/Files/"), fileName); txtFile.SaveAs(fileName); using (StreamReader r = new StreamReader(filePath)) { string json = r.ReadToEnd(); var details = JObject.Parse(json); List <string> notInsertedUsers = new List <string>(); List <UserTable> insertedUsers = new List <UserTable>(); UsersInserted ui = new UsersInserted(); foreach (var i in details["athlets"]) { if (_repository.UniqueBadgeNumber(i["badge_number"].ToString())) { string firstName = i["fist_name"].ToString(); string lastName = i["last_name"].ToString(); string dateOfBirth = i["date_of_birth"].ToString(); string nationality = i["nationality"].ToString(); string badgeNumber = i["badge_number"].ToString(); string photo = i["photo"].ToString(); string gender = i["gender"].ToString(); _repository.AddAthlete(firstName, lastName, dateOfBirth, nationality, badgeNumber, photo, gender); var user = _repository.GetSpecificUserByBadge(badgeNumber); UserTable ut = new UserTable(); ut.id = user.id; ut.firstName = user.firstName; ut.lastName = user.lastName; ut.badgeNumber = user.badgeNumber; insertedUsers.Add(ut); } else { notInsertedUsers.Add(i["badge_number"].ToString()); } } ui.users = insertedUsers; ViewBag.data = notInsertedUsers; return(View("Index", ui)); } }
public ActionResult GetAthletes() { var listOfAthletes = _repository.GetAthletes(); UsersInserted ui = new UsersInserted(); ui.users = listOfAthletes.Select(x => new UserTable { id = x.id, firstName = x.firstName, lastName = x.lastName, nationality = x.nationality, badgeNumber = x.badgeNumber, sports = x.OlympicSports.Select(y => new OlympicSports { id = y.id, nameOfSport = y.nameOfSport }).ToList() }).ToList(); return(View("Athletes", ui)); }
public ActionResult SaveCompetition(FormCollection collection) { if (_repository.UniqueCompetitionName((collection["nameOfCompetition"])) && collection["nameOfCompetition"] != "" && collection["description"] != "" && collection["sport"] != "" && collection["startDate"] != "" && collection["time"] != "") { _repository.SaveCompetition(collection["nameOfCompetition"], collection["description"], collection["sport"], collection["startDate"], collection["time"]); var competition = _repository.GetCompetition(collection["nameOfCompetition"]); for (int i = 5; i < collection.Count; i++) { var badge = collection[i]; _repository.AssignCompetitionToAthlete(badge, competition); } var competitions = _repository.GetAllCompetitions(); Competitions com = new Competitions(); com.competitions = competitions.Select(x => new CompetitionTable { id = x.id, nameOfCompetition = x.nameOfCompetition, sportName = x.sportName, startDate = x.startDate, time = x.time, status = x.status, athletes = x.TableOfUsers.Select(y => new UserTable { id = y.id, badgeNumber = y.badgeNumber, firstName = y.firstName, lastName = y.lastName, nationality = y.nationality }).ToList() }).ToList(); return(View("CompetitionList", com)); } else { var specAthletes = _repository.GetSpecificAthletes(collection["sport"]); UsersInserted users = new UsersInserted(); users.users = specAthletes.Select(x => new UserTable { id = x.id, firstName = x.firstName, lastName = x.lastName, badgeNumber = x.badgeNumber, nationality = x.nationality }).ToList(); ViewBag.sport = collection["sport"]; ViewBag.error = "Choose another competition name or fill the inputs!"; return(View("AddCompetitionDetails", users)); } }