public JsonResult DeleteTest(long id) { try { if (id > 0) { TestAthleteListViewModel model = new TestAthleteListViewModel(); model.ID = id; using (var repository = new WebApiClientRepository <TestAthleteListViewModel>()) { var payload = repository.GlobalApiCallPost(model, "api/Test/DeleteTest"); if (payload != null) { return(Json(new { Success = true, Message = "Athlete is Deleted successfully" })); } return(Json(new { Success = true, Message = "Athlete is Deleted successfully" })); } } else { return(Json(new { Success = true, Message = "Something went wrong !! Please Try later." })); } } catch (Exception ex) { return(Json(new { Success = false, Message = "Athlete can not be deleted now!" })); } }
public ActionResult Create(AddContinentDto model) { try { if (ModelState.IsValid) { ContinentDto continent = new ContinentDto(); using (var repository = new WebApiClientRepository <ContinentDto>()) { var response = repository.Post(model, "Continent"); if (response != null) { if (response.data != null) { continent = JsonConvert.DeserializeObject <ContinentDto>(response.data.ToString()); TempData["message_data"] = response.message; return(RedirectToAction(nameof(Index))); } else { TempData["message_data"] = response.message; return(RedirectToAction(nameof(Index))); } } } } // TODO: Add insert logic here TempData["message_data"] = "Problem on Athlete adding"; return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult CreateAthleteTest(TestAthleteViewModel model) { try { if (ModelState.IsValid) { PayloadResponse response = new PayloadResponse(); using (var repository = new WebApiClientRepository <PayloadResponse>()) { response = repository.GlobalApiCallPost(model, "api/Test/CreateTestAthlete"); if (response != null) { if (response.Success) { TempData["message_data_success"] = response.Message; return(RedirectToAction(nameof(Details), new { id = model.ID })); } else { TempData["message_data"] = response.Message; return(RedirectToAction(nameof(Details), new { id = model.ID })); } } } } // TODO: Add insert logic here TempData["message_data"] = "Problem on Athlete adding"; return(RedirectToAction(nameof(Details), new { id = model.ID })); } catch { return(View()); } }
public IActionResult Index() { TestViewModel model = new TestViewModel(); List <TestListViewModel> testList = new List <TestListViewModel>(); using (var repository = new WebApiClientRepository <List <TestListViewModel> >()) { int userID = 0; using (var storage = new LocalStorage()) { LoggedInUserInfo userInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); userID = userInfo.UserID; } var payload = repository.GlobalApiCallGet(null, "api/Test/GetTestListByCoach?id=" + userID); if (payload != null) { testList = payload.ToList(); } } model.TestList = testList; var testTypeList = GetTestType(); ViewBag.TestTypeID = new SelectList(testTypeList, "ID", "Name"); return(View(model)); }
public ActionResult EditAthleteTest(TestAthleteData data) { try { PayloadResponse response = new PayloadResponse(); TestAthleteListViewModel model = new TestAthleteListViewModel(); model.ID = Convert.ToInt64(data.TestAthleteID); model.Distance = Convert.ToInt32(data.Distance); if (ModelState.IsValid) { using (var repository = new WebApiClientRepository <PayloadResponse>()) { response = repository.GlobalApiCallPost(model, "api/Test/EditTestAthlete"); if (response != null) { TempData["message_data_success"] = response.Message; return(Ok(new { msg = response.Message })); } } } // TODO: Add insert logic here return(View()); } catch { return(View()); } }
private List <DropDownViewModel> GetTestType() { List <DropDownViewModel> typeList = new List <DropDownViewModel>(); using (var repository = new WebApiClientRepository <List <DropDownViewModel> >()) { var payload = repository.GlobalApiCallGet(null, "api/Test/GetTestTypes"); if (payload != null) { typeList = payload.ToList(); } } return(typeList); }
public IActionResult Details(long?id) { TestAthleteViewModel model = new TestAthleteViewModel(); using (var repository = new WebApiClientRepository <TestAthleteViewModel>()) { var payload = repository.GlobalApiCallGet(null, "api/Test/GetAthleteListByTestID?id=" + id); if (payload != null) { model = payload; } } ViewBag.AthleteID = new SelectList(GetAthlete(), "ID", "Name"); return(View(model)); }
public ActionResult Create(TestViewModel model) { try { if (ModelState.IsValid) { PayloadResponse response = new PayloadResponse(); using (var repository = new WebApiClientRepository <PayloadResponse>()) { using (var storage = new LocalStorage()) { LoggedInUserInfo userInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); model.CoachID = userInfo.UserID; } response = repository.GlobalApiCallPost(model, "api/Test/CreateTest"); if (response != null) { if (response.Success) { TempData["message_data_success"] = response.Message; return(RedirectToAction(nameof(Index))); } else { TempData["message_data"] = response.Message; return(RedirectToAction(nameof(Index))); } } else { TempData["message_data"] = "Problem on Test creation"; return(RedirectToAction(nameof(Index))); } } } else { TempData["message_data"] = "Problem on Test creation"; return(RedirectToAction(nameof(Index))); } } catch { TempData["message_data"] = "Problem on Test creation"; return(RedirectToAction(nameof(Index))); } }
// GET: Continent public IActionResult Index() { List <ContinentDto> continentList = new List <ContinentDto>(); using (var repository = new WebApiClientRepository <List <ContinentDto> >()) { var payload = repository.GetList(null, "Continent/GetList"); if (payload != null) { if (payload.data != null) { continentList = JsonConvert.DeserializeObject <List <ContinentDto> >(payload.data.ToString()); } } } return(View(continentList.ToList())); }
// GET: Continent/Edit/5 public ActionResult Edit(int id) { EditContinentDto continent = new EditContinentDto(); using (var repository = new WebApiClientRepository <EditContinentDto>()) { var payload = repository.GetById(id, "Continent/"); if (payload != null) { if (payload.data != null) { continent = JsonConvert.DeserializeObject <EditContinentDto>(payload.data.ToString()); } } } return(View(continent)); }
// GET: Continent/Create public ActionResult Create() { AddContinentDto continent = new AddContinentDto(); using (var repository = new WebApiClientRepository <TableConfigurationDto>()) { var payload = repository.GetList(null, "TableConfiguration/GetList"); if (payload != null) { if (payload.data != null) { continent.TableConfigurationDtos = JsonConvert.DeserializeObject <List <TableConfigurationDto> >(payload.data.ToString()); } } } return(View(continent)); }
public IActionResult Index(LoginViewModel model, string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); LoginResponseViewModel response = new LoginResponseViewModel(); using (var repository = new WebApiClientRepository <LoginResponseViewModel>()) { var payload = repository.GlobalApiCallPost(model, "login"); if (payload != null) { if (payload.successResonse != null) { string jwtToken = payload.successResonse.Token; var userInfo = payload.successResonse.User; using (var storage = new LocalStorage()) { storage.Store("jwtToken", jwtToken); storage.Store("userInfo", userInfo); } switch (userInfo.Role) { case "Coach": return(RedirectToAction(nameof(CoachController.Index), "Coach")); case "Athlete": return(RedirectToAction(nameof(AthleteController.Index), "Athlete")); default: ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View()); } } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View()); } } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View()); } } }
private List <DropDownViewModel> GetAthlete() { List <DropDownViewModel> athleteList = new List <DropDownViewModel>(); using (var repository = new WebApiClientRepository <List <DropDownViewModel> >()) { int userID = 0; using (var storage = new LocalStorage()) { LoggedInUserInfo userInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); userID = userInfo.UserID; } var payload = repository.GlobalApiCallGet(null, "api/Test/GetAllAthletesByCoachID?id=" + userID); if (payload != null) { athleteList = payload.ToList(); } } return(athleteList); }
public IActionResult Index() { AthleteTestViewModel model = new AthleteTestViewModel(); using (var repository = new WebApiClientRepository <AthleteTestViewModel>()) { int userID = 0; using (var storage = new LocalStorage()) { LoggedInUserInfo userInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); userID = userInfo.UserID; } var payload = repository.GlobalApiCallGet(null, "api/Test/GetTestListByAthlete?id=" + userID); if (payload != null) { model = payload; return(View(model)); } } return(View(model)); }
public IActionResult Index() { var token = string.Empty; var loggedInUserInfo = new LoggedInUserInfo(); using (var storage = new LocalStorage()) { if (storage.Exists("userInfo")) { loggedInUserInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString()); token = storage.Get("jwtToken").ToString(); } } if (string.IsNullOrEmpty(token)) { using (var storage = new LocalStorage()) { storage.Clear(); } return(View()); } PayloadResponse response = new PayloadResponse(); using (var repository = new WebApiClientRepository <PayloadResponse>()) { try { response = repository.GlobalApiCallPost(null, "api/Auth/KeepAlive"); if (response == null || !response.Success) { using (var storage = new LocalStorage()) { storage.Clear(); } return(View()); } } catch (Exception) { return(View()); } } if (loggedInUserInfo != null && loggedInUserInfo.UserID > 0) { switch (loggedInUserInfo.Role) { case "Coach": return(RedirectToAction(nameof(CoachController.Index), "Coach")); case "Athlete": return(RedirectToAction(nameof(AthleteController.Index), "Athlete")); default: ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View()); } } else { return(View()); } }