public ActionResult RegisterUserInRun(RunModel run) { UserModel user = UserHandler.GetUserDataByToken(Request.Headers["authorization"], true); string sqlProc = "exec RegisterUserInRun"; Dictionary <string, object> queryParams = new Dictionary <string, object> { { "@runId", run.Id }, { "@userId", user.Id }, { "@registerdSide", RegistredSide.user.ToString() } }; DbHandler dbHandler = new DbHandler(); dbHandler.GenerateProcedure(sqlProc, queryParams); sqlProc = dbHandler.AddParamsToQuery(sqlProc, queryParams); try { dbHandler.ExecuteQuery(sqlProc, queryParams); }catch (Exception e) { string response = JsonConvert.SerializeObject(new { id = run.Id, messege = e.Message }); return(Conflict(response)); } return(Ok()); }
public ActionResult PassChangerFromPanel(TempModel passedTempModel) { string tempNewPass = passedTempModel.userPass; UserModel newUserModel = null; //UserModel oldUserModel = GetUserInfoFromToken(passedTempModel.token); UserModel oldUserModel = UserHandler.GetUserDataByToken(passedTempModel.token); oldUserModel.UserPass = passedTempModel.oldPass; //oldUserModel = GetUserDataFromDbByLogin(oldUserModel.UserLogin); oldUserModel = UserHandler.GetUserDataFromDbByLogin(oldUserModel.UserLogin); oldUserModel.UserPass = passedTempModel.oldPass; newUserModel = AuthenticateUser(oldUserModel); if (newUserModel == null) { return(NotFound()); } var saltAsByte = GetSalt(); var saltAsString = Encoding.UTF8.GetString(saltAsByte, 0, saltAsByte.Length); var hashedPassword = HashPassword(saltAsByte, passedTempModel.userPass); newUserModel.UserPass = hashedPassword; newUserModel.UserSalt = saltAsString; try { UpdateUserDataInDB(newUserModel); }catch (Exception e) { return(Conflict()); } return(Ok()); }
public ActionResult AddCompetition(CompetitionModel competition) { UserModel owner = UserHandler.GetUserDataByToken(Request.Headers["authorization"]); owner = UserHandler.GetUserDataFromDbByLogin(owner.UserLogin); competition.ownerId = owner.Id; competition.ownerName = owner.UserName; #region dbAccess string sqlProc = "exec dbo.AddCompetition"; Dictionary <string, object> queryParams = new Dictionary <string, object> { { "@description", competition.description }, { "@startTime", competition.startTime.ToString("yyyy-MM-dd HH:mm") }, { "@endTime", competition.endTime.ToString("yyyy-MM-dd HH:mm") }, { "@placeOf", competition.placeOf }, { "@ownerId", competition.ownerId } }; DbHandler dbHandler = new DbHandler(); sqlProc = dbHandler.AddParamsToQuery(sqlProc, queryParams); try { UserModel userModel = new UserModel(); DataSet dataSet = dbHandler.GetSetFromDb(sqlProc, queryParams); return(Ok(competition)); } catch (Exception e) { return(Conflict(e.Message)); } #endregion return(Ok()); }
public ActionResult <IEnumerable <CompetitionDto> > GetAllCompetitionForUser() { UserModel user = UserHandler.GetUserDataByToken(Request.Headers["Authorization"]); user = _repositoryUsers.GetUserByLogin(user.UserLogin); var competition = _repositoryCompetition.GetAllCompetitionForUser(user.Id); return(Ok(_mapper.Map <IEnumerable <CompetitionDto> >(competition))); }
public ActionResult <IEnumerable <RunDto> > GetRunByCompetitionId(string id) { UserModel user = UserHandler.GetUserDataByToken(Request.Headers["authorization"]); user = _repositoryUsers.GetUserByLogin(user.UserLogin); var run = _repositoryRun.GetRunByCompetitionId(id); return(Ok(_mapper.Map <IEnumerable <RunDto> >(run))); }
public ActionResult addRun(RunModel run) { UserModel owner = UserHandler.GetUserDataByToken(Request.Headers["authorization"]); owner = _repositoryUsers.GetUserByLogin(owner.UserLogin); run.Id = Guid.NewGuid().ToString(); run.ownerId = owner.Id; _repositoryRun.Register(run); _repositoryRun.SaveChanges(); return(Ok()); }
public ActionResult GetRegistredUsersByRunId(RunModel runModel) { UserModel user = UserHandler.GetUserDataByToken(Request.Headers["authorization"], true); string sqlProc = "SELECT"; //Dictionary<string, object> queryParams = new Dictionary<string, object> { // { "@runId", run.Id}, // {"@userId", user.Id }, // {"@registerdSide", RegistredSide.user.ToString() } //}; return(Ok()); }
public ActionResult FindUserTargetsByToken(TempModel passedTempModel) { UserModel userModel = UserHandler.GetUserDataByToken(passedTempModel.token); userModel = UserHandler.GetUserDataFromDbByLogin(userModel.UserLogin); List <TargetModel> targetList = new List <TargetModel>(); try { targetList = ReadTargetFromDB(creator: userModel.Id); }catch (Exception e) { return(NotFound()); } TargetModel[] targets = targetList.ToArray(); //UnpackTargets(targets); return(Ok(targets)); }
public ActionResult <CompetitionDto> GetCompetitionById(string id) { UserModel user = UserHandler.GetUserDataByToken(Request.Headers["authorization"]); user = _repositoryUsers.GetUserByLogin(user.UserLogin); var competition = _repositoryCompetition.GetCompetitionById(id); if (competition != null) { if (user.UserType == UserType.person.ToString()) { return(Ok(_mapper.Map <CompetitionDto>(competition))); } if (competition.ownerId != user.Id && user.UserType == UserType.company.ToString()) { return(NotFound()); } return(Ok(_mapper.Map <CompetitionDto>(competition))); } return(NotFound()); }
public ActionResult AddCompetition(CompetitionModel competition) { UserModel owner = UserHandler.GetUserDataByToken(Request.Headers["authorization"]); owner = UserHandler.GetUserDataFromDbByLogin(owner.UserLogin); #region dbAccess string sqlProc = "exec dbo.AddCompetition"; Dictionary <string, object> queryParams = new Dictionary <string, object> { { "@description", competition.description }, { "@startTime", competition.startTime.ToString("yyyy-MM-dd HH:mm:ss.fff") }, { "@endTime", competition.endTime.ToString("yyyy-MM-dd HH:mm:ss.fff") }, { "@placeOf", competition.placeOf }, { "@ownerId", competition.ownerId } }; DbHandler dbHandler = new DbHandler(); dbHandler.GenerateProcedure(sqlProc, queryParams); dbHandler.GenerateQuerryValues(sqlProc, queryParams); sqlProc = dbHandler.AddParamsToQuery(sqlProc, queryParams); try { UserModel userModel = new UserModel(); DataSet dataSet = dbHandler.GetSetFromDb(sqlProc, queryParams); foreach (DataRow row in dataSet.Tables["tab"].Rows) { userModel.UserMail = row["UserMail"].ToString(); userModel.UserLogin = row["UserLogin"].ToString(); } return(Ok()); } catch (Exception e) { return(Conflict(e.Message)); } #endregion return(Ok()); }
public ActionResult <IEnumerable <RunDto> > GetRunByCompetitionId(string Id) { UserModel user = UserHandler.GetUserDataByToken(Request.Headers["authorization"], true); string sqlProc = "SELECT * FROM run (NOLOCK) WHERE competitionId = @competitionId"; Dictionary <string, object> queryParams = new Dictionary <string, object> { { "@competitionId", Id } }; DbHandler dbHandler = new DbHandler(); DataSet dataSet = dbHandler.GetSetFromDb(sqlProc, queryParams); int numberOfRuns = dataSet.Tables["tab"].Rows.Count; RunModel[] runModels = new RunModel[numberOfRuns]; int runIterator = 0; foreach (DataRow row in dataSet.Tables["tab"].Rows) { RunModel runModel = new RunModel(); runModel.competitionId = row["competitionId"].ToString(); runModel.Id = row["Id"].ToString(); runModel.ownerId = row["ownerId"].ToString(); runModel.description = row["description"].ToString(); runModel.target = row["target"].ToString(); runModel.noOfShots = int.Parse(row["noOfShots"].ToString()); runModels[runIterator] = runModel; runIterator++; } //RunModel[] runModels = GetRunsByCompIdAndUserID(Id, user.Id); return(Ok(runModels)); //user = _repositoryUsers.GetUserByLogin(user.UserLogin); //var run = _repositoryRun.GetRunByCompetitionId(id); //return Ok(_mapper.Map<IEnumerable<RunDto>>(run)); }