bool IPriceService.UpdatePrice(EditPriceModel WebPageData) { using (var GiftEntity = new GiftEntities()) { int IdToSearchFor = Convert.ToInt32(WebPageData.DatabaseID); Price PriceToUpdate = (from c in GiftEntity.Prices where c.ID == IdToSearchFor select c).FirstOrDefault(); if (PriceToUpdate == null) { throw new Exception("Trying to update a Price that does not exist"); } PriceToUpdate.PricingName = WebPageData.PricingName; PriceToUpdate.CardPrice = Convert.ToDecimal(WebPageData.CardPrice); PriceToUpdate.TransactionPrice = Convert.ToDecimal(WebPageData.TransactionPrice); PriceToUpdate.SupportTransactionPrice = Convert.ToDecimal(WebPageData.SupportTransactionPrice); PriceToUpdate.GiftMonthlyFee = Convert.ToDecimal(WebPageData.GiftMonthlyFee); PriceToUpdate.CardholderMonthlyFee = Convert.ToDecimal(WebPageData.CardholderMonthlyFee); PriceToUpdate.CardHolderPercentageCharge = Convert.ToInt32(WebPageData.CardHolderPercentageCharge); PriceToUpdate.AfterXMonths = Convert.ToInt32(WebPageData.AfterXMonths); //GiftEntity.Prices.ApplyCurrentValues(PriceToUpdate); GiftEntity.SaveChanges(); //SaveOptions.AcceptAllChangesAfterSave return(true); } }
bool IClerkDAO.UpdateClerk(Clerk ToUpdate) { using (var GiftEntity = new GiftEntities()) { GiftEntity.Clerks.Attach(ToUpdate); GiftEntity.SaveChanges(); //SaveOptions.AcceptAllChangesAfterSave return(true); } }
// // RoleProvider.RemoveUsersFromRoles // public override void RemoveUsersFromRoles(string[] usernames, string[] rolenames) { foreach (string rolename in rolenames) { if (!RoleExists(rolename)) { throw new ProviderException("Role name not found."); } } foreach (string username in usernames) { foreach (string rolename in rolenames) { if (!IsUserInRole(username, rolename)) { throw new ProviderException("User is not in role."); } } } try { using (var GiftEntity = new GiftEntities()) { foreach (string username in usernames) { foreach (string rolename in rolenames) { var nRole = (from r in GiftEntity.UsersInRoles where r.Rolename == rolename && r.Username == username && r.ApplicationName == pApplicationName select r).FirstOrDefault(); if (nRole == null) { continue; } GiftEntity.UsersInRoles.Remove(nRole); } } GiftEntity.SaveChanges(); } } catch (Exception e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "RemoveUsersFromRoles"); } else { throw e; } } }
bool IUserDAO.CreateUser(User UserToAdd) { using (var GiftEntity = new GiftEntities()) { UserToAdd.PKID = Guid.NewGuid(); GiftEntity.Users.Add(UserToAdd); GiftEntity.SaveChanges(); return(true); } }
void IHistoryDAO.DeleteHistoryItem(int ID) { using (var GiftEntity = new GiftEntities()) { History DBHistory = (from c in GiftEntity.Histories where c.ID == ID select c).FirstOrDefault(); GiftEntity.Histories.Remove(DBHistory); GiftEntity.SaveChanges(); } }
void IClerkDAO.DeleteClerk(int ID) { using (var GiftEntity = new GiftEntities()) { var clerk = GiftEntity.Clerks.FirstOrDefault(d => d.ID == ID); if (clerk == null) { return; } GiftEntity.Clerks.Remove(clerk); GiftEntity.SaveChanges(); } }
void IUserInRolesDAO.DeleteUserFromRole(String UserName) { using (var GiftEntity = new GiftEntities()) { UsersInRole DBUserInRole = (from c in GiftEntity.UsersInRoles where c.Username == UserName select c).FirstOrDefault(); if (DBUserInRole == null) { return; } GiftEntity.UsersInRoles.Remove(DBUserInRole); GiftEntity.SaveChanges(); } }
void IUserDAO.UpdateUserOnline(Guid ID) { using (var GiftEntity = new GiftEntities()) { User DBUser = (from c in GiftEntity.Users where c.PKID == ID select c).FirstOrDefault(); if (DBUser == null) { return; } DBUser.LastActivityDate = DateTime.Now; GiftEntity.SaveChanges(); } }
bool IClerkDAO.CreateClerk(String MerchantID, Clerk ToAdd) { using (var GiftEntity = new GiftEntities()) { Guid MerchGUID = GiftEntity.Merchants.FirstOrDefault(d => d.MerchantID == MerchantID).MerchantGUID; if (MerchGUID == null) { throw new Exception("Invalid merchant id " + MerchantID); } ToAdd.MerchantGUID = MerchGUID; GiftEntity.Clerks.Add(ToAdd); GiftEntity.SaveChanges(); return(true); } }
bool IUserDAO.DeleteUser(string UserName) { using (var GiftEntity = new GiftEntities()) { User DBUser = (from c in GiftEntity.Users where c.UserName == UserName select c).FirstOrDefault(); if (DBUser == null) { return(false); } GiftEntity.Users.Remove(DBUser); GiftEntity.SaveChanges(); } return(true); }
bool IUserDAO.UpdatePassword(String UserName, String NewPassword) { using (var GiftEntity = new GiftEntities()) { User DBUser = (from c in GiftEntity.Users where c.UserName == UserName select c).FirstOrDefault(); if (DBUser == null) { return(false); } DBUser.Password = NewPassword; DBUser.LastPasswordChangedDate = DateTime.Now; GiftEntity.SaveChanges(); } return(true); }
bool IUserDAO.UnlockUser(String UserName) { using (var GiftEntity = new GiftEntities()) { User DBUser = (from c in GiftEntity.Users where c.UserName == UserName select c).FirstOrDefault(); if (DBUser == null) { return(false); } DBUser.LastLockedOutDate = DateTime.Now; DBUser.IsLockedOut = false; GiftEntity.SaveChanges(); } return(true); }
public void AddUserToRole(String username, String RoleName, String ApplicationName) { if (IsUserInRole(username, RoleName, ApplicationName)) { throw new Exception("User is already in role."); } using (var GiftEntity = new GiftEntities()) { UsersInRole UR = new UsersInRole(); UR.Username = username; UR.Rolename = RoleName; UR.ApplicationName = ApplicationName; GiftEntity.UsersInRoles.Add(UR); GiftEntity.SaveChanges(); } }
bool IUserDAO.UpdatePasswordAnswerFailureCount(String UserName, int PasswordAttemptWindow, int MaxInvalidPasswordAttempts) { using (var GiftEntity = new GiftEntities()) { User DBUser = (from c in GiftEntity.Users where c.UserName == UserName select c).FirstOrDefault(); if (DBUser == null) { return(false); } // update the failure count for the password answer DateTime windowStart = new DateTime(); DateTime windowEnd = windowStart.AddMinutes(PasswordAttemptWindow); // First password answer failure or outside of PasswordAttemptWindow. // Start a new password answer failure count from 1 and a new window starting now. if (DBUser.FailedPasswordAnswerAttemptCount == 0 || DateTime.Now > windowEnd) { DBUser.FailedPasswordAnswerAttemptCount = 1; DBUser.FailedPasswordAnswerAttemptWindowStart = DateTime.Now; } else { // Password answer attempts have exceeded the failure threshold. Lock out // the user. if (DBUser.FailedPasswordAnswerAttemptCount + 1 >= MaxInvalidPasswordAttempts) { DBUser.IsLockedOut = true; DBUser.LastLockedOutDate = DateTime.Now; } else // Password answer attempts have not exceeded the failure threshold. Update // the failure counts. Leave the window the same. { DBUser.FailedPasswordAnswerAttemptCount = DBUser.FailedPasswordAnswerAttemptCount + 1; } } GiftEntity.SaveChanges(); } return(true); }
// This is impossible to do with encrypted data // List<CardHolder> ICardHolderRepository.GetCardHolderPage(int pageNumber, int pageSize) // { // List<CardHolder> CardHolderList = new List<CardHolder>(); // using (var GiftEntity = new GiftEntities()) // { // var CardHolderPage = (from c in GiftEntity.CardHolders // .OrderBy(o => o.CardHolderName) // .Skip(pageSize * pageNumber).Take(pageSize).Select(o => o) // select c); // foreach (CardHolder ch in CardHolderPage) // CardHolderList.Add(ch); // } // return CardHolderList; // } // the problem is how to do the "like" clause when the field is encrypted // List<CardHolder> ICardHolderRepository.ListCardHoldersLike(String CardHolderName, int pageNumber, int pageSize) // { // using (var GiftEntity = new GiftEntities()) // { // List<CardHolder> ToReturn = new List<CardHolder>(); // foreach (CardHolder ch in (from c in GiftEntity.CardHolders // .OrderBy(o => o.CardHolderName) // .Skip(pageSize * pageNumber).Take(pageSize).Select(o => o) // where c.CardHolderName.StartsWith(CardHolderName) // select c)) // { // ToReturn.Add(ch); // } // return ToReturn; // } // } // List<CardHolder> ICardHolderRepository.ListCardHoldersLikeEmail(String CardHolderEmail, int pageNumber, int pageSize) // { // using (var GiftEntity = new GiftEntities()) // { // List<CardHolder> ToReturn = new List<CardHolder>(); // foreach (CardHolder ch in (from c in GiftEntity.CardHolders // .OrderBy(o => o.CardHolderName) // .Skip(pageSize * pageNumber).Take(pageSize).Select(o => o) // where c.email.StartsWith(CardHolderEmail) // select c)) // { // ToReturn.Add(ch); // } // return ToReturn; // } // } bool ICardHolderRepository.DeleteCardHolder(string CardHolderName) { String EncryptedCardHolderName = GiftEncryption.Encrypt(CardHolderName); using (var GiftEntity = new GiftEntities()) { CardHolder DBCardHolder = (from c in GiftEntity.CardHolders where c.EncryptedCardHolderName == EncryptedCardHolderName select c).FirstOrDefault(); if (DBCardHolder == null) { return(false); } GiftEntity.CardHolders.Remove(DBCardHolder); GiftEntity.SaveChanges(); } return(true); }
bool IUserDAO.UpdateEmail(String UserName, String email, String comment, bool isapproved) { using (var GiftEntity = new GiftEntities()) { User DBUser = (from c in GiftEntity.Users where c.UserName == UserName select c).FirstOrDefault(); if (DBUser == null) { return(false); } DBUser.Email = email; DBUser.Comment = comment; DBUser.IsApproved = isapproved; GiftEntity.SaveChanges(); } return(true); }
public void InsureSuperUserRoleExists(String ApplicationName) { using (var GiftEntity = new GiftEntities()) { var nRole = (from r in GiftEntity.Roles where r.Rolename == "SystemAdministrator" && r.ApplicationName == ApplicationName select r).FirstOrDefault(); if (nRole == null) { Role nr = GiftEntity.Roles.Create(); nr.ApplicationName = ApplicationName; nr.Rolename = "SystemAdministrator"; GiftEntity.Roles.Add(nr); GiftEntity.SaveChanges(); } } }
// // RoleProvider.DeleteRole // public override bool DeleteRole(string rolename, bool throwOnPopulatedRole) { if (!RoleExists(rolename)) { throw new ProviderException("Role does not exist."); } if (throwOnPopulatedRole && GetUsersInRole(rolename).Length > 0) { throw new ProviderException("Cannot delete a populated role."); } try { using (var GiftEntity = new GiftEntities()) { var nRole = (from r in GiftEntity.Roles where r.Rolename == rolename && r.ApplicationName == pApplicationName select r).FirstOrDefault(); if (nRole == null) { return(false); } GiftEntity.Roles.Remove(nRole); GiftEntity.SaveChanges(); } } catch (Exception e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "DeleteRole"); return(false); } else { throw e; } } return(true); }
bool IUserDAO.ChangePasswordQuestionAndAnswer(string UserName, string newPwdQuestion, string newPwdAnswer) { using (var GiftEntity = new GiftEntities()) { User DBUser = (from c in GiftEntity.Users where c.UserName == UserName select c).FirstOrDefault(); if (DBUser == null) { return(false); } DBUser.LastPasswordChangedDate = DateTime.Now; DBUser.PasswordQuestion = newPwdQuestion; DBUser.PasswordAnswer = newPwdAnswer; GiftEntity.SaveChanges(); } return(true); }
// // RoleProvider.CreateRole // public override void CreateRole(string rolename) { if (rolename.Contains(",")) { throw new ArgumentException("Role names cannot contain commas."); } if (RoleExists(rolename)) { throw new ProviderException("Role name already exists."); } try { Role nRole = new Role(); nRole.Rolename = rolename; nRole.ApplicationName = pApplicationName; using (var GiftEntity = new GiftEntities()) { GiftEntity.Roles.Add(nRole); GiftEntity.SaveChanges(); } } catch (Exception e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "CreateRole"); } else { throw e; } } }
/// <summary> /// Saves all the changes /// </summary> public void SaveChanges() { GiftEntity.SaveChanges(); }
bool IUserDAO.ValidateUserByEmail(String emailAddress, String Password, int PasswordAttemptWindow, int MaxInvalidPasswordAttempts, out String userName) { bool isValid = false; userName = ""; using (var GiftEntity = new GiftEntities()) { User DBUser = (from c in GiftEntity.Users where c.Email == emailAddress select c).FirstOrDefault(); if (DBUser == null) { return(false); } if (CheckPassword(Password, DBUser.Password)) { if ((bool)DBUser.IsApproved) { DBUser.LastLoginDate = DateTime.Now; GiftEntity.SaveChanges(); userName = DBUser.UserName; isValid = true; } else { isValid = false; } } else { // update the failure count for the password DateTime windowStart = new DateTime(); DateTime windowEnd = windowStart.AddMinutes(PasswordAttemptWindow); // First password failure or outside of PasswordAttemptWindow. // Start a new password failure count from 1 and a new window starting now. if (DBUser.FailedPasswordAttemptCount == 0 || DateTime.Now > windowEnd) { DBUser.FailedPasswordAttemptCount = 1; DBUser.FailedPasswordAttemptWindowStart = DateTime.Now; } else { // Password attempts have exceeded the failure threshold. Lock out // the user. if (DBUser.FailedPasswordAttemptCount + 1 >= MaxInvalidPasswordAttempts) { DBUser.IsLockedOut = true; DBUser.LastLockedOutDate = DateTime.Now; } else // Password attempts have not exceeded the failure threshold. Update // the failure counts. Leave the window the same. { DBUser.FailedPasswordAttemptCount = DBUser.FailedPasswordAttemptCount + 1; } } GiftEntity.SaveChanges(); isValid = false; } } return(isValid); }