コード例 #1
0
        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"));
        }
コード例 #2
0
ファイル: UserService.cs プロジェクト: jzaja/BetterConnect
        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);
        }
コード例 #3
0
 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());
 }
コード例 #4
0
 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);
 }
コード例 #5
0
        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();
            }
        }