Example #1
0
        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());
        }
Example #2
0
        public ActionResult ValidateUser(string code)
        {
            string sqlProc = "exec dbo.ValidateUser";
            Dictionary <string, object> queryParams = new Dictionary <string, object> {
                { "@Code", code }
            };
            DbHandler dbHandler = new DbHandler();

            sqlProc = dbHandler.AddParamsToQuery(sqlProc, queryParams);
            try
            {
                DataSet dataSet = dbHandler.GetSetFromDb(sqlProc, queryParams);
                return(Ok(new { Result = "Confirmation ok" }));
            }
            catch (Exception e)
            {
                return(Conflict(new { Result = "Code is not good" }));
            }



            //CodeModel codeModel = _repositoryCodes.GetCodeModelByCode(code);
            //bool codeIsValid = CodeHandler.IsCodeValid(codeModel, MailType.varyfication);
            //if (codeIsValid)
            //{
            //    UserModel userModel = _repositoryUsers.GetUserById(codeModel.UserId);
            //    UserModel userModelToSave = new UserModel();
            //    userModel.Confirmed = true;
            //    userModelToSave = userModel;
            //    ChangeUserData(userModelToSave, userModel);

            //    CodeModel usedCode = _repositoryCodes.GetCodeModelByCode(code);
            //    CodeModel CodeModelToSave = CodeHandler.DeactivateCode(usedCode, userModel);

            //    ChangeCodeData(CodeModelToSave, usedCode);
            //}
        }
Example #3
0
        static public UserModel GetUserDataFromDbByLogin(string login)
        {
            UserModel userModel = new UserModel();
            string    sqlProc   = "SELECT * FROM Users WHERE UserLogin = @UserLogin";
            Dictionary <string, object> queryParams = new Dictionary <string, object> {
                { "@UserLogin", login }
            };
            DbHandler dbHandler = new DbHandler();

            try
            {
                DataSet dataSet = dbHandler.GetSetFromDb(sqlProc, queryParams);
                foreach (DataRow row in dataSet.Tables["tab"].Rows)
                {
                    userModel.Id               = row["Id"].ToString();
                    userModel.UserType         = row["UserType"].ToString();
                    userModel.UserLogin        = row["UserLogin"].ToString();
                    userModel.UserPass         = row["UserPass"].ToString();
                    userModel.UserName         = row["UserName"].ToString();
                    userModel.UserSureName     = row["UserSureName"].ToString();
                    userModel.UserTaxNumber    = row["UserTaxNumber"].ToString();
                    userModel.UserAddress      = row["UserAddress"].ToString();
                    userModel.UserCity         = row["UserCity"].ToString();
                    userModel.UserZipCode      = row["UserZipCode"].ToString();
                    userModel.UserMail         = row["UserMail"].ToString();
                    userModel.UserPhoneNumber  = row["UserPhoneNumber"].ToString();
                    userModel.UserPhoneNumber2 = row["UserPhoneNumber2"].ToString();
                    userModel.UserSalt         = row["UserSalt"].ToString();
                    userModel.UserRole         = row["UserRole"].ToString();
                    userModel.Confirmed        = Convert.ToBoolean(row["Confirmed"]);
                }
            }
            catch (Exception e)
            {
            }
            return(userModel);
        }
Example #4
0
        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));
        }