public TokenResult GenerateToken(string PhoneNumber, string Password, string UserId, string RefreshTokenStr) { JavaScriptSerializer jss = new JavaScriptSerializer(); TokenResult tokenResult = new TokenResult(); tokenResult = jss.Deserialize <TokenResult>(GeneralFunctions.GETDataNew(Models.Constants.Token, "grant_type=password&username="******"&password=" + Password)); var RefreshToken = new RefreshToken(); using (AuthRepository _repo = new AuthRepository()) { if (string.IsNullOrEmpty(RefreshTokenStr)) { RefreshToken = _repo.AddRefreshToken(UserId, tokenResult.access_token); tokenResult.refresh_token = RefreshToken.ProtectedTicket; } else { RefreshToken refreshToken = new RefreshToken(); refreshToken = _ctx.RefreshTokens.Where(x => x.UserId == UserId && x.ProtectedTicket == RefreshTokenStr).FirstOrDefault(); if (refreshToken != null) { refreshToken.ExpiresUtc = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00).AddHours(Constants.TimeOfExpireRefreshTokenHours); refreshToken.IssuedUtc = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00); _ctx.SaveChanges(); } tokenResult.refresh_token = RefreshTokenStr; } tokenResult.id = UserId; } tokenResult.result = true; return(tokenResult); }
void setQuestion() { Reset(); lbscore.Text = score.ToString(); if (quizzes.Count > 0) { qNumber++; lbnumber.Text = qNumber.ToString(); int quizNumb = _random.Next(0, quizzes.Count); quiz = quizzes[quizNumb]; lbquestion.Text = quiz.Question_Text; op1.Text = quiz.OptionA; op2.Text = quiz.OptionB; op3.Text = quiz.OptionC; op4.Text = quiz.OptionD; if (quizType == "Flag") { pictureBox1.Image = Image.FromFile("flags/" + quiz.Answer + ".png"); } } else { MessageBox.Show("Thank you, Your score is : " + score + ". Your score has been saved..!"); QuizScore qscore = new QuizScore(); qscore.UserId = Global.LoggedInUserId; qscore.Score = score; qscore.QuizDate = DateTime.Now; Entities.QuizScores.Add(qscore); Entities.SaveChanges(); btnMenu.Enabled = true; } }
public void paytmJob() { var data = entities.Transactions.Where(x => x.WithdrawType == "Paytm" && x.paymentStatus == "Pending").ToList(); string hostName = Dns.GetHostName(); // Retrive the Name of HOST string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString(); // Get the IP GeneralFunctions general = new GeneralFunctions(); var earn = general.getEarningHeads(); foreach (var item in data) { int amount = (int)item.amount - earn.WithdrawCharges; if (amount > 0) { var pay = PaytmResponse(item.mobilenumber, "Withdrawal Amount in Paytm", amount.ToString(), myIP); var paytmResult = JsonConvert.DeserializeObject <paytmResponse.Root>(pay); if (paytmResult.statusCode == "SUCCESS" && paytmResult.status == "SUCCESS") { item.paymentStatus = "withdrawal"; } item.PaytmOrderId = paytmResult.orderId; item.PaytmResponse = pay; ////db.Entry(old).CurrentValues.SetValues(model); ////return db.SaveChanges() > 0; /// //entities.SaveChanges(); entities.Entry(item).CurrentValues.SetValues(item); entities.SaveChanges(); } } }
public bool AddOTP(ForgotPasswordBindingModel model) { var mobile = entities.AspNetUsers.Where(x => x.PhoneNumber == model.PhoneNumber).FirstOrDefault(); if (mobile != null) { using (QuizAppEntities entities = new QuizAppEntities()) { var OTP = GeneralFunctions.GetOTP(); MobileOTP mobileOTP = new MobileOTP() { PhoneNumber = model.PhoneNumber, OTP = OTP, CreatedDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), }; entities.MobileOTPs.Add(mobileOTP); var OtpSend = sms_api_callAsync(model.PhoneNumber, OTP.ToString()); return(entities.SaveChanges() > 0); } } else { return(false); } }
public void Add(QuizItemQuestionAnswer model) { using (var context = new QuizAppEntities()) { context.QuizItemQuestionAnswers.Add(model); context.SaveChanges(); } }
public void CheckDeviceId(User model, string DeviceId) { if (model.DeviceID == null || model.DeviceID == string.Empty) { model.DeviceID = DeviceId; entities.SaveChanges(); } }
public bool PassCodeSave(RegisterBindingModel model) { var data = entities.Users.Where(x => x.UserID == model.UserId).FirstOrDefault(); if (data != null) { data.Passcode = model.Passcode; entities.SaveChanges(); return(true); } else { return(false); } }
public int Add(QuizItemQuestion model) { using (var context = new QuizAppEntities()) { context.QuizItemQuestions.Add(model); context.SaveChanges(); return(model.Id); } }
public int Add(QuizTaking model) { using (var context = new QuizAppEntities()) { context.QuizTakings.Add(model); context.SaveChanges(); return(model.Id); } }
public void Delete(int id) { using (var context = new QuizAppEntities()) { var existingEntity = context.QuizItemQuestionAnswers.FirstOrDefault(o => o.Id == id); if (existingEntity != null) { context.QuizItemQuestionAnswers.Remove(existingEntity); context.SaveChanges(); } } }
public void Update(QuizItemQuestion model) { using (var context = new QuizAppEntities()) { var existingEntity = context.QuizItemQuestions.FirstOrDefault(o => o.Id == model.Id); if (existingEntity == null) { return; } context.Entry(existingEntity).CurrentValues.SetValues(model); context.SaveChanges(); } }
public bool UpdatePassword(string UserId, string Password) { using (QuizAppEntities model = new QuizAppEntities()) { var userInfo = model.Users.Where(x => x.UserID == UserId).FirstOrDefault(); if (userInfo != null) { userInfo.Password = Password; userInfo.LastUpdateDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00); model.Entry(userInfo).State = EntityState.Modified; return(model.SaveChanges() > 0); } else { return(false); } } }
private void btnReg_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbFullName.Text) || string.IsNullOrEmpty(loginid.Text) || string.IsNullOrEmpty(password.Text)) { MessageBox.Show("Please fill All Fields"); } else { SysUser user = new SysUser(); user.FullName = tbFullName.Text; user.Username = loginid.Text; user.Password = password.Text; quizAppEntities.SysUsers.Add(user); quizAppEntities.SaveChanges(); MessageBox.Show("Registered Successfully..!"); tbFullName.Text = string.Empty; loginid.Text = string.Empty; password.Text = string.Empty; } }
public ChallangeIdModel ChallangePost(ChallangeModel model) { var Challange = new Entities.Challange() { UserId = model.UserId, Name = model.Name, Phone = model.Phone, IsAdmin = true, IsAccepted = true, StartDateTime = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), IsCompleted = false, CompletedDateTime = null, IsWinner = false, Points = 0 }; entities.Challanges.Add(Challange); entities.SaveChanges(); int ChallangeId = Challange.Id; var data = entities.Challanges.Where(x => x.Id == ChallangeId).FirstOrDefault(); if (data != null) { data.ChallangeId = ChallangeId; entities.SaveChanges(); } return(new ChallangeIdModel() { ChallangeId = data.Id }); }
public TokenResult RegisterUser(RegisterBindingModel model) { try { var Otp = GeneralFunctions.GetOTP(); //Set By Defaulte Admin Refferal Code When User Not Use Any Refferal Code if (model.UsedReferalCode == null || model.UsedReferalCode == "" || model.UsedReferalCode == string.Empty) { string AdminId = ConfigurationManager.AppSettings["Admin"].ToString(); model.UsedReferalCode = ConfigurationManager.AppSettings["RefferalCode"].ToString(); } var ParentIDs = GetParentsIDsFromReferalCode(model.UsedReferalCode, model.UserId); using (QuizAppEntities entities = new QuizAppEntities()) { User registerUser = new User() { Name = model.Name, Password = model.Password, UserID = model.UserId, CreatedDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), LastUpdateDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), ReferalCode = GeneralFunctions.GetReferalCode(), DeviceID = model.DeviceID, IP = model.IP, isActive = true, isBlocked = false, NotificationKey = model.NotificationKey, otp = Otp.ToString(), ParentIDs = ParentIDs, Platform = model.Platform, UsedReferalCode = model.UsedReferalCode.ToLower(), }; var OtpSend = sms_api_callAsync(model.PhoneNumber, Otp.ToString()); MobileOTP mobileOTP = new MobileOTP() { PhoneNumber = model.PhoneNumber, OTP = Otp, CreatedDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00) }; entities.MobileOTPs.Add(mobileOTP); entities.Users.Add(registerUser); int updatedRow = entities.SaveChanges(); var UserId = registerUser.UserID; if (updatedRow >= 1) { //Add Registration Income var jsonFilePath = HttpContext.Current.Server.MapPath("~/Models/JsonFile/LevelEarningMasterUser.json"); EaningHeadModel earningHeads = new EaningHeadModel(); using (StreamReader r = new StreamReader(jsonFilePath)) { string json = r.ReadToEnd(); earningHeads = JsonConvert.DeserializeObject <EaningHeadModel>(json); } var data = (from U in entities.Users join A in entities.AspNetUsers on U.UserID equals A.Id where U.UserID == UserId select new UserTransactionModel() { UserName = U.Name, MobileNumber = A.UserName }).FirstOrDefault(); var uniqueKey = $"{UserId}~{DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00).ToString("dd-MM-yyy")}~Earning"; Transaction transaction = new Transaction() { UserID = UserId, transactionDateTime = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), UniqueKey = uniqueKey, paymentStatus = "Earning", amount = earningHeads.RegistrationIncome, comment = "Registration Income Amount", username = data.UserName, mobilenumber = data.MobileNumber }; entities.Transactions.Add(transaction); entities.SaveChanges(); AuthRepository authRepository = new AuthRepository(); return(authRepository.GenerateToken(model.PhoneNumber, model.Password, model.UserId, "")); } else { TokenResult result = new TokenResult(); result.result = false; result.error_message = "User registration failed."; return(result); } } } catch (Exception ex) { TokenResult result = new TokenResult(); result.result = false; result.error_message = ex.Message; return(result); } }