public int RegisterUser(UserMaster user) { if (user.UserID == 0) { user.IsActive = true; user.AccountStatus = 1; user.Password = string.IsNullOrEmpty(user.Password) ? "123456" : user.Password; user.CreatedDate = DateTime.Now; HIQAdminContext.UserMasters.Add(user); return(HIQAdminContext.SaveChanges() > 0 ? user.UserID : 0); } UserMaster User = HIQAdminContext.UserMasters.FirstOrDefault(x => x.UserID == user.UserID); User.ModifiedBy = user.ModifiedBy; User.ModifiedDate = DateTime.Now; User.Password = user.Password; User.Address = user.Address; User.City = user.City; User.Mobile = user.Mobile; User.Phone = user.Phone; User.Pin = user.Pin; User.Image = user.Image; User.IsDeleted = user.IsDeleted; HIQAdminContext.Entry(User).State = EntityState.Modified; return(HIQAdminContext.SaveChanges() > 0 ? user.UserID : 0); }
public int AddUpdateStudentInvoice(StudentInvoice student) { if (student.ID == 0) { student.CreatedDate = DateTime.Now; HIQAdminContext.StudentInvoices.Add(student); } else { var invoice = HIQAdminContext.StudentInvoices.FirstOrDefault(x => x.ID == student.ID); if (invoice != null) { invoice.Name = student.Name; invoice.PaymentMode = student.PaymentMode; invoice.PaymentStatus = student.PaymentStatus; invoice.Mobile = student.Mobile; invoice.Status = student.Status; invoice.SubTotal = student.SubTotal; invoice.ModifiedDate = DateTime.Now; HIQAdminContext.Entry(invoice).State = EntityState.Modified; } } return(HIQAdminContext.SaveChanges() > 0 ? student.UserID : 0); }
/// <summary> /// save OTP (One Time Password) to database /// </summary> /// <param name="otp"> Object of OTP</param> /// <returns>returns true when data is saved</returns> public bool SaveOTP(OTPMaster otp) { bool IsSuccess = false; // In case from Generating OTP from Automatic redirect to Change Password because of not complex password multiple OTPs can be generated // Use this validation to restrict user to generate multiple OTPs if (ValidateUser(otp.UserID, AspectEnums.UserValidationType.LastAttemptDuration)) { HIQAdminContext.Entry(otp).State = EntityState.Added; IsSuccess = HIQAdminContext.SaveChanges() > 0; } return(IsSuccess); }
/// <summary> /// Change password of User /// </summary> /// <param name="GUID"> uniqe string </param> /// <param name="Password">password entered by user</param> /// <returns></returns> public bool ChangePassword(string GUID, string Password) { int OTPExirationHrs = Convert.ToInt32(AppUtil.GetAppSettings(AspectEnums.ConfigKeys.OTPExirationHrs)); DateTime StartTime = DateTime.Now.Subtract(new TimeSpan(OTPExirationHrs, 0, 0)); DateTime EndTime = DateTime.Now; OTPMaster objOTP = HIQAdminContext.OTPMasters.FirstOrDefault(k => k.CreatedDate >= StartTime && k.CreatedDate <= EndTime && k.GUID == GUID); if (objOTP != null) { UserMaster user = HIQAdminContext.UserMasters.FirstOrDefault(k => k.UserID == objOTP.UserID && !k.IsDeleted); user.Password = EncryptionEngine.EncryptString(Password); HIQAdminContext.Entry(user).State = EntityState.Modified; //Delete all previous OTPs foreach (var o in HIQAdminContext.OTPMasters.Where(k => k.UserID == user.UserID)) { HIQAdminContext.OTPMasters.Remove(o); } return(HIQAdminContext.SaveChanges() > 0); } return(false); }
/// <summary> /// Authenticate OTP (One Time Password) entered by user /// </summary> /// <param name="userid">Userid</param> /// <param name="otp">One Time Password</param> /// <returns>reurns true if user have enterered latest OTP</returns> public bool AuthenticateOTP(long userid, string otp, out string GuidString, out int MaxAttempts) { OTPMaster ObjOTP = HIQAdminContext.OTPMasters.OrderByDescending(k => k.CreatedDate).FirstOrDefault(k => k.UserID == userid); GuidString = ""; MaxAttempts = 0; if (ObjOTP != null) { MaxAttempts = ObjOTP.Attempts.Value; if (ObjOTP.OTP == otp) { GuidString = ObjOTP.GUID; return(true); } ObjOTP.Attempts = ++MaxAttempts; HIQAdminContext.Entry(ObjOTP).State = EntityState.Modified; HIQAdminContext.SaveChanges(); // TBD } //} return(false); }