Esempio n. 1
0
        /// <summary>
        /// Deletes an activity log item
        /// </summary>
        /// <param name="activityLog">Activity log type</param>
        public virtual void DeleteActivity(ActivityLog activityLog)
        {
            if (activityLog == null)
                throw new ArgumentNullException("activityLog");

            _activityLogRepository.Delete(activityLog);
        }
 public new void SetUp()
 {
     _activityType1 = new ActivityLogType
     {
         Id = 1,
         SystemKeyword = "TestKeyword1",
         Enabled = true,
         Name = "Test name1"
     };
     _activityType2 = new ActivityLogType
     {
         Id = 2,
         SystemKeyword = "TestKeyword2",
         Enabled = true,
         Name = "Test name2"
     };
     _customer1 = new Customer
     {
         Id = 1,
         Email = "*****@*****.**",
         Username = "******",
         Deleted = false,
     };
        _customer2 = new Customer
        {
        Id = 2,
        Email = "*****@*****.**",
        Username = "******",
        Deleted = false,
        };
     _activity1 = new ActivityLog
     {
         Id = 1,
         ActivityLogType = _activityType1,
         CustomerId = _customer1.Id,
         Customer = _customer1
     };
     _activity2 = new ActivityLog
     {
         Id = 2,
         ActivityLogType = _activityType1,
         CustomerId = _customer2.Id,
         Customer = _customer2
     };
     _cacheManager = new NopNullCache();
     _workContext = MockRepository.GenerateMock<IWorkContext>();
     _webHelper = MockRepository.GenerateMock<IWebHelper>();
     _activityLogRepository = MockRepository.GenerateMock<IRepository<ActivityLog>>();
     _activityLogTypeRepository = MockRepository.GenerateMock<IRepository<ActivityLogType>>();
     _activityLogTypeRepository.Expect(x => x.Table).Return(new List<ActivityLogType> { _activityType1, _activityType2 }.AsQueryable());
     _activityLogRepository.Expect(x => x.Table).Return(new List<ActivityLog> { _activity1, _activity2 }.AsQueryable());
     _customerActivityService = new CustomerActivityService(_cacheManager, _activityLogRepository, _activityLogTypeRepository, _workContext, null, null, null, _webHelper);
 }
        /// <summary>
        /// Inserts an activity log item
        /// </summary>
        /// <param name="systemKeyword">The system keyword</param>
        /// <param name="comment">The activity comment</param>
        /// <param name="customer">The customer</param>
        /// <param name="commentParams">The activity comment parameters for string.Format() function.</param>
        /// <returns>Activity log item</returns>
        public virtual ActivityLog InsertActivity(string systemKeyword, int entityKeyId,
            string comment, Customer customer, params object[] commentParams)
        {
            if (customer == null)
                return null;

            var activityTypes = GetAllActivityTypesCached();
            var activityType = activityTypes.ToList().Find(at => at.SystemKeyword == systemKeyword);
            if (activityType == null || !activityType.Enabled)
                return null;

            comment = CommonHelper.EnsureNotNull(comment);
            comment = string.Format(comment, commentParams);
            comment = CommonHelper.EnsureMaximumLength(comment, 4000);

            
            var activity = new ActivityLog();
            activity.ActivityLogTypeId = activityType.Id;
            activity.CustomerId = customer.Id;
            activity.EntityKeyId = entityKeyId;
            activity.Comment = comment;
            activity.CreatedOnUtc = DateTime.UtcNow;
            activity.ActivityLogType = new ActivityLogType();
            activity.ActivityLogType.Id = activityType.Id;
            activity.ActivityLogType.Name = activityType.Name;
            activity.ActivityLogType.SystemKeyword = activityType.SystemKeyword;

            _activityLogRepository.Insert(activity);

            return activity;
        }
Esempio n. 4
0
        /// <summary>
        /// Inserts an activity log item
        /// </summary>
        /// <param name="systemKeyword">The system keyword</param>
        /// <param name="comment">The activity comment</param>
        /// <param name="commentParams">The activity comment parameters for string.Format() function.</param>
        /// <returns>Activity log item</returns>
        public virtual ActivityLog InsertActivity(string systemKeyword, 
            string comment, params object[] commentParams)
        {
            if (_workContext.CurrentCustomer == null)
                return null;

            var activityTypes = GetAllActivityTypes();
            var activityType = activityTypes.ToList().Find(at => at.SystemKeyword == systemKeyword);
            if (activityType == null || !activityType.Enabled)
                return null;

            comment = CommonHelper.EnsureNotNull(comment);
            comment = string.Format(comment, commentParams);
            comment = CommonHelper.EnsureMaximumLength(comment, 4000);

            var activity = new ActivityLog();
            activity.ActivityLogType = activityType;
            activity.Customer = _workContext.CurrentCustomer;
            activity.Comment = comment;
            activity.CreatedOnUtc = DateTime.UtcNow;

            _activityLogRepository.Insert(activity);

            return activity;
        }