/// <summary> /// Function to delete a CategoryEntity from database. /// </summary> /// <param name="categoryEntity">CategoryEntity to delete</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the CategoryEntity was deleted successfully, the same CategoryEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="categoryEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public CategoryEntity Delete(CategoryEntity categoryEntity, string session) { bool permited = ValidationService.Instance.ValidatePermission(session, "delete", "Category"); if (!permited) { ExceptionDetail detail = new ExceptionDetail(new UtnEmall.Server.BusinessLogic.UtnEmallPermissionException("The user hasn't permissions to delete an entity")); throw new FaultException <ExceptionDetail>(detail); } if (categoryEntity == null) { throw new ArgumentException("The argument can not be null or be empty"); } try { // Delete categoryEntity using data access object categoryDataAccess.Delete(categoryEntity); // Delete related customers' preference PreferenceDataAccess preferenceDataAccess = new PreferenceDataAccess(); foreach (PreferenceEntity preferenceEntity in preferenceDataAccess.LoadWhere(PreferenceEntity.DBIdCategory, categoryEntity.Id, false, OperatorType.Equal)) { preferenceDataAccess.Delete(preferenceEntity); } return(null); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmall.Server.BusinessLogic.UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }
public Preference Set(string key, object value, bool isPublic) { if (!BaseSecurity.IsSysAdmin(Context)) { throw new ChalkableSecurityException(ChlkResources.ERR_PREFERENCE_INVALID_RIGHTS); } using (var uow = Update()) { var da = new PreferenceDataAccess(uow); var preference = da.GetPreferenceOrNull(key); if (preference == null) { preference = CreatePreference(isPublic, key, new PreferenceInfo { Category = cache[key].Category, Type = cache[key].Type, Value = value.ToString(), Hint = cache[key].Hint }); da.Insert(preference); } else { preference.Value = value.ToString(); preference.IsPublic = isPublic; da.Update(preference); } cache[key] = preference; uow.Commit(); return(preference); } }
private void SetPreferences(IList <Preference> preferences) { using (var uow = Update()) { var da = new PreferenceDataAccess(uow); var forInsert = preferences.Where(p => !cache.ContainsKey(p.Key)).ToList(); da.Insert(forInsert); foreach (var p in forInsert) { cache.Add(p.Key, p); } uow.Commit(); } }
public static void AddNewPreferencesDueToNewCategory(CategoryEntity category) { // Add the preferences to all the clients. CustomerDataAccess customerDataAccess = new CustomerDataAccess(); PreferenceDataAccess preferenceDataAccess = new PreferenceDataAccess(); foreach (CustomerEntity customer in customerDataAccess.LoadAll(false)) { PreferenceEntity preference = new PreferenceEntity(); preference.Active = true; preference.Level = 0; preference.Category = category; preference.IdCustomer = customer.Id; preference.IsNew = true; preferenceDataAccess.Save(preference); } }
static PreferenceService() { var defaultList = DefaultList(); using (var uow = new UnitOfWork(Settings.MasterConnectionString, false, IsolationLevel.ReadCommitted)) { var preferences = new PreferenceDataAccess(uow).GetAll(); foreach (var defaultelem in defaultList) { var preference = preferences.FirstOrDefault(x => x.Key == defaultelem.Key); var p = preference ?? CreatePreference(false, defaultelem.Key, defaultelem.Value); cache.Add(p.Key, p); } foreach (var preference in preferences) { if (!cache.ContainsKey(preference.Key)) { cache.Add(preference.Key, preference); } } } }
private void UpdateProfiles() { while (true) { // Espera un periódo de tiempo Thread.Sleep(minutesBetweenUpdates * 60000); Collection <CustomerEntity> customers = new CustomerDataAccess().LoadAll(true); // Para cada cliente, obtener la última acción almacenada foreach (CustomerEntity customer in customers) { DateTime lastUserActionDate = DateTime.MinValue; List <UserActionEntity> userActions = new List <UserActionEntity>(new UserActionDataAccess().LoadByCustomerCollection(customer.Id)); foreach (UserActionEntity userAction in userActions) { if (userAction.Timestamp > lastUserActionDate) { lastUserActionDate = userAction.Timestamp; } } Collection <PreferenceEntity> preferences = new PreferenceDataAccess().LoadByCustomerCollection(customer.Id); foreach (PreferenceEntity preference in preferences) { if (lastUserActionDate > preference.Timestamp) { // Actualizar todos los niveles si la última actualización del cliente es menor // a la última acción registrada. preference.Level = AppraiseCategory(customer, preference.Category); new PreferenceDataAccess().Save(preference); } } } } }