public void TestGetByName() { var interest = new Interest { Name = "Skijanje" }; _interestRepo.Save(interest); Assert.NotNull(_interestRepo.GetByName("skijanje")); Assert.NotNull(_interestRepo.GetByName("Skijanje")); Assert.NotNull(_interestRepo.GetByName("SkIjAnjE")); Assert.Null(_interestRepo.GetByName("nepostojece")); }
public User AddInterest(int userId, string interestName) { User user = (User)_userRepo.Get(userId); Interest interest = _interestRepository.GetByName(interestName); if (user.Interests.Contains(interest)) { return(null); } if (interest == null) { Interest newInterest = new Interest { Name = interestName }; var saved = _interestRepository.Save(newInterest); saved.AddUser(user); _interestRepository.Update(saved); } else { interest.AddUser(user); _interestRepository.Update(interest); } return(user); }
public int Delete(string deletelist) { string[] list = deletelist.TrimEnd(',').Split(','); foreach (var item in list) { _repository.Delete(_repository.Get(int.Parse(item))); } return(_repository.Save()); }
public bool InsertInterest(string userId, InterestDto interest) { try { //Validate user if (_userRepository.IsAuthenticated(userId)) { //Validate Model ICollection <ValidationResult> results; if (IsValidModel(interest, out results)) { //Call Repository if (_interestRepository.InsertInterest(interest)) { //Save if (_interestRepository.Save()) { //Success return(true); } _loggingService.Info("Failed To Save"); } _loggingService.Info("UserRepository Failed Insert"); } _loggingService.Info("Model Validation Failed: " + interest); } _loggingService.Info("UserId Authenticated Failed: " + userId); } catch (Exception ex) { //Error _loggingService.Error("An error has occurred", ex); } //Fail return(false); }
public void GenerateBalanceWithInterest(Balance balance, DateTime date) { using (_balanceRepository.BeginTransaction()) { //Save Interes if (balance.Total < 0) { var interest = balance.Total * TX_INTEREST * (-1); _interestRepository.Save(new Interest(interest, date, balance.Account)); balance.Total += interest; balance.Charges.Add(new ShortEntryDTO(DateTime.Today, interest)); } var yesterday = _balanceRepository.LastByOrDefault(balance.Account, date.AddDays(-1)); balance.UpdateDayPosition(yesterday.Total); balance.Closed = true; _balanceRepository.Update(balance); _balanceRepository.Commit(); } }