public bool DeleteList(int listId) { List list = new List(); if (listId > 0) { using (var scope = new TransactionScope()) { var cachedList = ApplicationCache <ListDescriptionTO> .GetCacheItem(d => d.Id == listId); if (cachedList != null) { ApplicationCache <ListDescriptionTO> .RemoveCacheItem(cachedList); } var cachedRating = ApplicationCache <ListFilmRating> .GetCacheItem(d => d.ListId == listId); if (cachedRating != null) { ApplicationCache <ListFilmRating> .RemoveCacheItem(cachedRating); } bool result = _listRepository.Delete(listId); if (result == true) { scope.Complete(); return(true); } } } return(false); }
public bool ChangeEmail(ChangeEmailTO emailDetails) { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var result = _authRepository.ChangeEmail(emailDetails.OldEmail, emailDetails.NewEmail); if (result) { scope.Complete(); var cacheItem = ApplicationCache <UserInfoTO> .GetCacheItem(d => d.Email == emailDetails.OldEmail); if (cacheItem != null) { var newCacheItem = new UserInfoTO() { Id = cacheItem.Id, Email = emailDetails.NewEmail, UserName = cacheItem.UserName, Roles = cacheItem.Roles }; ApplicationCache <UserInfoTO> .RemoveCacheItem(cacheItem); ApplicationCache <UserInfoTO> .AddCacheItem(newCacheItem); } return(true); } return(false); } }
public bool DeleteRating(RatingShortDescriptionTO rating) { var success = false; if (rating.Rate == -1 || rating.Rate == 1) { using (var scope = new TransactionScope()) { var rate = new Rating(); var cache = ApplicationCache <Rating> .GetCache(); if (cache.Count() > 0) { var cacheItem = cache.Where(d => d.List.Id == rating.ListId && d.User.UserName == rating.UserName).FirstOrDefault(); if (cacheItem != null) { ApplicationCache <Rating> .RemoveCacheItem(cacheItem); } } success = _listRepository.DeleteRating(rating.ListId, rating.UserName); scope.Complete(); } if (success == true) { using (var scope = new TransactionScope()) { _listRepository.UpdateLikesDislikesCount(rating.ListId, false, false, true); //update cache ListDescriptionTO var cache = ApplicationCache <ListDescriptionTO> .GetCache(); if (cache.Count() > 0) { var cacheItem = cache.FirstOrDefault(d => d.Id == rating.ListId); if (cacheItem != null) { //update likes cacheItem.Likes = _listRepository.GetLikesCount(rating.ListId); //update dislikes cacheItem.DisLikes = _listRepository.GetDislikesCount(rating.ListId); var listIndex = cache.FindIndex(d => d.Id == rating.ListId); // replace object cache[listIndex] = cacheItem; ApplicationCache <ListDescriptionTO> .FillCache(cache); } } scope.Complete(); } return(true); } } return(false); }
public bool DeleteUser(string userName) { var result = _authRepository.DeleteUser(userName); if (result) { var cacheItem = ApplicationCache <UserInfoTO> .GetCacheItem(d => d.UserName == userName); if (cacheItem != null) { ApplicationCache <UserInfoTO> .RemoveCacheItem(cacheItem); } return(true); } return(false); }