public void ChangeAchievement(AccountDTO account_dto) { if (account_dto == null) throw new ArgumentNullException("account_dto"); var account = Mapper.Map<Account>(account_dto); var achievement = new Achievement(account); if (achievement.Year.Year < DateTime.Now.Year) { // TODO: throw custermized exception return; } IUnityContainer container = new UnityContainer(); IRepository<Account> accountRepository = container.Resolve<IRepository<Account>>(); if (accountRepository.Get(achievement.AccountId) != null) { using (TransactionScope scope = new TransactionScope()) { IRepository<Achievement> achievementRepository = container.Resolve<IRepository<Achievement>>(); achievementRepository.TrackEntity(achievement); achievementRepository.Commit(); var history = new AchievementHistory(achievement); IRepository<AchievementHistory> archievementHistoryRepository = container.Resolve<IRepository<AchievementHistory>>(); archievementHistoryRepository.Add(history); archievementHistoryRepository.Commit(); var changeTimes = archievementHistoryRepository.GetFiltered(a => a.AccountId == achievement.Id).Count<AchievementHistory>(); if (changeTimes > 2) { var accountLock = Mapper.Map<Account>(account_dto); accountRepository.TrackEntity(accountLock); accountLock.LockAccount(); accountRepository.Commit(); } scope.Complete(); } } }
public void ChangeAchievement(AccountDTO account_dto) { if (account_dto == null) throw new ArgumentNullException("account_dto"); AccountRepository accountRepository = new AccountRepository(); var account = accountRepository.Get(account_dto.Id); if (account != null) { var achievement = new Achievement(account); achievement.ACEENumber = account_dto.ACEENumber; achievement.Score = account_dto.Score; achievement.SpecialityType = account_dto.SpecialityType; achievement.Province = account_dto.Zone.Province; achievement.City=account_dto.Zone.City; accountService.ChangeAchievement(account, achievement); accountRepository.Commit(); } }
public void ChangeAchievement(Achievement achievement) { using (UserRepository userRepository = new UserRepository()) { var user = userRepository.Get(achievement.UserId); if (user != null) { var _achievement = user.Achievements.SingleOrDefault<Achievement>(a => a.Year == DateTime.Now.Year && a.UserId == user.Id); if (_achievement != null) { var id = _achievement.Id; _achievement = Mapper.Map<Achievement>(achievement); _achievement.Id = id; } else user.Achievements.Add(achievement); userRepository.Commit(); } } }
/// <summary> /// Deprecated Method for adding a new object to the Achievements EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToAchievements(Achievement achievement) { base.AddObject("Achievements", achievement); }
/// <summary> /// Create a new Achievement object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="score">Initial value of the Score property.</param> /// <param name="year">Initial value of the Year property.</param> /// <param name="courseType">Initial value of the CourseType property.</param> /// <param name="userId">Initial value of the UserId property.</param> /// <param name="highSchoolId">Initial value of the HighSchoolId property.</param> /// <param name="provinceId">Initial value of the ProvinceId property.</param> public static Achievement CreateAchievement(global::System.Int32 id, global::System.Double score, global::System.Int32 year, global::System.String courseType, global::System.Guid userId, global::System.Guid highSchoolId, global::System.Guid provinceId) { Achievement achievement = new Achievement(); achievement.Id = id; achievement.Score = score; achievement.Year = year; achievement.CourseType = courseType; achievement.UserId = userId; achievement.HighSchoolId = highSchoolId; achievement.ProvinceId = provinceId; return achievement; }