/// <summary>
        /// 获取接收人UserId集合
        /// </summary>
        /// <param name="activityService">动态业务逻辑类</param>
        /// <param name="activity">动态对象</param>
        /// <returns></returns>
        IEnumerable <long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
        {
            List <long> followerUserIds = subscribeService.GetUserIdsOfObject(activity.OwnerId).ToList();

            if (followerUserIds == null)
            {
                followerUserIds = new List <long>();
            }

            //将动态发送者(回答的作者)从动态的接收对象中移除(否则如果动态发送者也关注了该问题,就会产生重复的动态数据)
            if (followerUserIds.Contains(activity.UserId))
            {
                followerUserIds.Remove(activity.UserId);
            }

            //如果用户没有设置从默认设置获取
            ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);

            if (activityItem != null)
            {
                isUserReceived = activityItem.IsUserReceived;
            }

            return(followerUserIds.Where(n => IsReceiveActivity(activityService, n, activity)));
        }
        public void GetActivityById_WhenTheActivityExists()
        {
            //Arrange
            myActivityRepository.Expect(x => x.GetAll()).Return(new List <Activity>
            {
                new Activity {
                    ActivityId = 1, Description = "Activity 1", TeamId = 5
                },
                new Activity {
                    ActivityId = 2, Description = "Activity 2", TeamId = 5
                }
            }.AsQueryable()).Repeat.Once();

            myUnitOfWork.Expect(x => x.GetGenericRepository <Activity>()).Return(myActivityRepository).Repeat.Once();
            myUnitOfWorkFactory.Expect(x => x.GetUnitOfWork()).Return(myUnitOfWork).Repeat.Once();

            var ActivityService = new ActivityService
            {
                UnitOfWorkFactory = myUnitOfWorkFactory
            };

            //Act

            var result = ActivityService.GetActivityById(2);

            //Asserts
            Assert.AreEqual(StatusCode.Successful, result.StatusCode);
            Assert.AreEqual(2, result.Data.ActivityId);
            Assert.AreEqual("Activity 2", result.Data.Description);
            Assert.AreEqual(5, result.Data.TeamId);
            myUnitOfWork.VerifyAllExpectations();
            myUnitOfWorkFactory.VerifyAllExpectations();
            myActivityRepository.VerifyAllExpectations();
        }
Пример #3
0
 public ActionResult RetrieveCampaignRules(int campaignId)
 {
     try
     {
         using (MCContext ctx = new MCContext())
         {
             var campaignRules = ctx.campaignRules
                                 .Where(x => x.campaignId == campaignId)
                                 .Select(x => new
             {
                 x.id,
                 x.activationDay,
                 atLeastPrice = x.atLeastPrice + " TL",
                 x.count,
                 x.description,
                 x.index,
                 x.name,
                 ruleType = x.ruleType == Enums.RuleTypes.percentage ? "%" : "TL"
             })
                                 .OrderBy(x => x.index)
                                 .ToList();
             if (campaignRules.Any())
             {
                 return(Json(campaignRules, JsonRequestBehavior.AllowGet));
             }
             return(Json(null, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         ActivityService.LogException(ex);
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "İşlem sırasında bir hata oluştu."));
     }
 }
Пример #4
0
 public ActionResult RetrieveUserInvitations()
 {
     try
     {
         var userId = Convert.ToInt32(Session["CurrentUserId"]);
         using (MCContext ctx = new MCContext())
         {
             var invitations = ctx.userInvitations
                               .Where(x => x.referenceUserId == userId)
                               .OrderByDescending(x => x.id)
                               .Select(x => new
             {
                 x.mailAddress,
                 x.invitationStatus,
                 x.createdDate
             })
                               .ToList();
             return(Json(invitations, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         ActivityService.LogException(ex);
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "İşlem sırasında bir hata oluştu."));
     }
 }
        public void SelectUptoThreeActivities_Below_Three_Return_False_Test()
        {
            IUserService         _userService         = new UserService(_context);
            IActivityService     _activityService     = new ActivityService(_context);
            IUserActivityService _userActivityService = new UserActivityService(_context);
            ApplicationUser      user = new ApplicationUser {
                UserName = "******"
            };
            bool userSaveResult = _userService.AddUser(user);

            RecretionalActivity kayaking = new RecretionalActivity {
                ActivityName = "Kayaking"
            };

            _activityService.AddAnActivity(kayaking);
            RecretionalActivity camping = new RecretionalActivity {
                ActivityName = "Camping"
            };

            _activityService.AddAnActivity(camping);

            if (userSaveResult)
            {
                _userActivityService.ChooseAnActivity(user, kayaking);
                _userActivityService.ChooseAnActivity(user, camping);
            }

            bool selectUpToThreeActivities = _userActivityService.CanChooseUptoThreeActivities(user);

            Assert.IsFalse(selectUpToThreeActivities);
        }
        public void BadgeAwardedActivityGet()
        {
            const string guidStr     = "515b7240-3be1-43d4-8846-c0b589cd1cd2";
            const string guidStrUser = "******";

            var timestamp           = DateTime.UtcNow;
            var activityRepository  = Substitute.For <IActivityRepository>();
            var badgeActivitiesInDb = new List <Activity>
            {
                new Activity
                {
                    Type      = ActivityType.BadgeAwarded.ToString(),
                    Timestamp = timestamp,
                    Data      = BadgeActivity.KeyBadgeId + "=" + guidStr + "," + BadgeActivity.KeyUserId + "=" + guidStrUser
                }
            };
            var pagedBadgeActivities = new PagedList <Activity>(badgeActivitiesInDb, 1, 20, 1);

            activityRepository.GetPagedGroupedActivities(1, 20).Returns(pagedBadgeActivities);
            _badgeRepository.Get(new Guid(guidStr)).Returns(new Badge());
            _membershipRepository.Get(new Guid(guidStrUser)).Returns(new MembershipUser());

            IActivityService activityService = new ActivityService(activityRepository, _badgeRepository, _membershipRepository, _loggingService);

            var badgeActivities = activityService.GetPagedGroupedActivities(1, 20);

            Assert.IsTrue(badgeActivities[0] is BadgeActivity);
        }
Пример #7
0
        private void lv_rooster_lecturers_SelectedIndexChanged(object sender, EventArgs e)
        {
            lv_rooster_activity.Clear();
            lv_rooster_replacement.Clear();
            btn_replacement.Enabled = false;

            if (lv_rooster_lecturers.SelectedItems.Count > 1)
            {
                lv_rooster_lecturers.SelectedItems[0].Selected = false;
            }
            else if (lv_rooster_lecturers.SelectedItems.Count == 1)
            {
                ActivityService activityService = new ActivityService();

                lv_rooster_activity.Clear();
                lv_rooster_activity.Columns.Add("Omschrijving");
                lv_rooster_activity.Columns[0].Width *= 2;
                lv_rooster_activity.Columns.Add("Studenten");
                lv_rooster_activity.Columns.Add("Begeleiders");
                lv_rooster_activity.Columns.Add("ID");

                foreach (Activity activity in activityService.GetActivitiesByLecturer(Int32.Parse(lv_rooster_lecturers.SelectedItems[0].SubItems[1].Text)))
                {
                    ListViewItem li = new ListViewItem(activity.Omschrijving);
                    li.SubItems.Add(activity.AantalStudenten.ToString());
                    li.SubItems.Add(activity.AantalBegeleiders.ToString());
                    li.SubItems.Add(activity.Id.ToString());
                    lv_rooster_activity.Items.Add(li);
                }
            }
        }
Пример #8
0
 public HomeController(ILogger <HomeController> logger,
                       ServiceFacade.Controller context,
                       ActivityService activityService,
                       DailyLiteracyTipService dailyLiteracyTipService,
                       DashboardContentService dashboardContentService,
                       DynamicAvatarService dynamicAvatarService,
                       EmailReminderService emailReminderService,
                       PageService pageService,
                       SiteService siteService,
                       UserService userService)
     : base(context)
 {
     _logger                  = Require.IsNotNull(logger, nameof(logger));
     _activityService         = Require.IsNotNull(activityService, nameof(activityService));
     _dailyLiteracyTipService = Require.IsNotNull(dailyLiteracyTipService,
                                                  nameof(dailyLiteracyTipService));
     _dashboardContentService = Require.IsNotNull(dashboardContentService,
                                                  nameof(dashboardContentService));
     _dynamicAvatarService = Require.IsNotNull(dynamicAvatarService,
                                               nameof(dynamicAvatarService));
     _emailReminderService = Require.IsNotNull(emailReminderService,
                                               nameof(emailReminderService));
     _pageService = Require.IsNotNull(pageService, nameof(pageService));
     _siteService = Require.IsNotNull(siteService, nameof(siteService));
     _userService = Require.IsNotNull(userService, nameof(userService));
 }
        //public HttpResponseMessage GetActivityByOrderNumbers([FromUri] string[] id)
        public IHttpActionResult GetActivityByOrderNumbers(List <OrderStuff> orderStuff)
        {
            //IEnumerable<Models.OrderListViewItem> orders = Models.Order.ToListView(JobManager.Services.OrderService.GetRecentOrders());
            var activityList = ActivityService.GetActivitiesByOrderNumber(orderStuff).ToList();

            return(Ok(activityList));
        }
        public IHttpActionResult CreateActivity(Activity activity)
        {
            // todo:  switch from IHttpActionResult to HttpResponseMessage


            IMember member = null;

            try
            {
                // set token in header in postman ,  but logged into application
                // then it is fine
                var memberService = ApplicationContext.Current.Services.MemberService;
                var memberId      = Members.GetCurrentMember().Id;
                member = memberService.GetById(memberId);
                activity.CreatedById   = memberId;
                activity.CreatedByName = member.Name;
            }
            catch (Exception exception)
            {
                string ex = exception.ToString();
            }



            var ret = ActivityService.CreateActivity(activity, member);

            return(Ok(ret));
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        public ActionResult PersonalPlanList(Guid id)
        {
            var semester = SemesterService.GetSemester(id);
            var user     = AppUser;

            var courseService = new CourseService(Db);

            var model = new DashboardStudentViewModel();

            model.Semester = semester;
            model.User     = user;
            model.Student  = StudentService.GetCurrentStudent(user);
            model.Courses  = new List <CourseSummaryModel>();

            var courses = Db.Activities.OfType <Course>().Where(a =>
                                                                a.SemesterGroups.Any(g => g.Semester.Id == semester.Id) &&
                                                                a.Occurrence.Subscriptions.Any(u => u.UserId.Equals(model.User.Id))).ToList();

            foreach (var course in courses)
            {
                var summary = courseService.GetCourseSummary(course);
                model.Courses.Add(summary);

                var state = ActivityService.GetActivityState(course.Occurrence, user);

                summary.User         = user;
                summary.Subscription = state.Subscription;

                summary.Lottery =
                    Db.Lotteries.FirstOrDefault(x => x.Occurrences.Any(y => y.Id == course.Occurrence.Id));
            }

            return(View(model));
        }
Пример #12
0
        public PartialViewResult Faculty(Guid facultyId)
        {
            var user        = GetCurrentUser();
            var member      = MemberService.GetMember(user.Id, facultyId);
            var newsletters = Db.Activities.OfType <Newsletter>().Where(x => x.Organiser.Id == facultyId).ToList();

            var model = new List <NewsletterViewModel>();

            var userRight = new UserRight();

            userRight.User   = UserManager.FindByName(User.Identity.Name);
            userRight.Member = member;

            var semester = SemesterService.GetSemester(DateTime.Today);

            foreach (var newsletter in newsletters)
            {
                bool isMember = (member != null);
                bool isAdmin  = (member != null) && member.IsNewsAdmin;

                model.Add(new NewsletterViewModel
                {
                    Newsletter = newsletter,
                    State      = ActivityService.GetActivityState(newsletter.Occurrence, AppUser),
                    IsMember   = isMember,
                    IsAdmin    = isAdmin,
                });
            }

            ViewBag.UserRight = userRight;
            ViewBag.Curricula = Db.Curricula.ToList();
            ViewBag.Semester  = semester;

            return(PartialView("_NewsletterList", model));
        }
Пример #13
0
        public ActionResult DeleteCampaignRule(int campaignRuleId)
        {
            try
            {
                using (MCContext ctx = new MCContext())
                {
                    var rule = ctx.campaignRules.FirstOrDefault(x => x.id == campaignRuleId);
                    if (rule == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Böyle bir veri mevcut değildir."));
                    }

                    var enableToDelete = ctx.userReferenceOrders.FirstOrDefault(x => x.campaignRuleId == campaignRuleId && x.userReference.campaign.isActive && x.userReference.status != Enums.ReferenceStatus.passive) == null;
                    if (!enableToDelete)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Conflict, "Silmek istediğiniz kural aktif bir siparişe atandığı için silemezsiniz."));
                    }
                    ctx.campaignRules.Remove(rule);
                    ctx.SaveChanges();
                    return(Json(new { responseText = "Kural başarıyla silindi." }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                ActivityService.LogException(ex);
                return(Json(new { message = "İşlem sırasında bir hata oluştu.", state = "error" }, JsonRequestBehavior.AllowGet));
            }
        }
        public void GetActivityById_WhenTheActivityDoesNotExist()
        {
            //Arrange
            myActivityRepository.Expect(x => x.GetAll()).Return(new List <Activity> {
                new Activity {
                    ActivityId = 1, Description = "Activity 1"
                }
            }.AsQueryable()).Repeat.Once();
            myUnitOfWork.Expect(x => x.GetGenericRepository <Activity>()).Return(myActivityRepository).Repeat.Once();
            myUnitOfWorkFactory.Expect(x => x.GetUnitOfWork()).Return(myUnitOfWork).Repeat.Once();

            var activityService = new ActivityService
            {
                UnitOfWorkFactory = myUnitOfWorkFactory
            };

            //Act

            var result = activityService.GetActivityById(56);

            //Asserts
            Assert.AreEqual(StatusCode.Error, result.StatusCode);
            Assert.IsNull(result.Data);
            myUnitOfWork.VerifyAllExpectations();
            myUnitOfWorkFactory.VerifyAllExpectations();
            myActivityRepository.VerifyAllExpectations();
        }
Пример #15
0
        private void btn_replacement_Click(object sender, EventArgs e)
        {
            int oldLecturerId = Int32.Parse(lv_rooster_lecturers.SelectedItems[0].SubItems[1].Text);
            int newLecturerId = Int32.Parse(lv_rooster_replacement.SelectedItems[0].SubItems[1].Text);
            int activityId    = Int32.Parse(lv_rooster_activity.SelectedItems[0].SubItems[3].Text);

            ActivityService activityService = new ActivityService();

            activityService.ChangeActivityLecturer(activityId, newLecturerId, oldLecturerId);

            lv_rooster_activity.Clear();

            foreach (Activity activity in activityService.GetActivitiesByLecturer(Int32.Parse(lv_rooster_lecturers.SelectedItems[0].SubItems[1].Text)))
            {
                ListViewItem li = new ListViewItem(activity.Omschrijving);
                li.SubItems.Add(activity.AantalStudenten.ToString());
                li.SubItems.Add(activity.AantalBegeleiders.ToString());
                li.SubItems.Add(activity.Id.ToString());
                lv_rooster_activity.Items.Add(li);
            }

            LecturerService lecturerService = new LecturerService();

            lv_rooster_replacement.Clear();

            foreach (Lecturer lecturer in lecturerService.getLecturers())
            {
                if (lv_rooster_lecturers.SelectedItems[0].SubItems[0].Text != lecturer.name)
                {
                    ListViewItem li = new ListViewItem(lecturer.name);
                    li.SubItems.Add(lecturer.number.ToString());
                    lv_rooster_replacement.Items.Add(li);
                }
            }
        }
Пример #16
0
        public static async Task <IActionResult> GetAllActivityFunc(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "activity")] HttpRequest req,
            [SwaggerIgnore][CosmosDB(ConnectionStringSetting = "cosmos-bl-tutorial-serverless")] DocumentClient client,
            ILogger log)
        {
            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <Activity, ActivityDTO>();
            });

            IMapper mapper = new Mapper(config);

            ActivityService activityservice = new ActivityService(new Repositories.ActivityRepository(client));

            var activities = await activityservice.GetAllActivity();

            var activityList = new List <ActivityDTO>();

            foreach (var item in activities.Items)
            {
                activityList.Add(mapper.Map <ActivityDTO>(item));
            }

            var result = new GetAllActivityResponse();

            result.ContinuationToken = activities.ContinuationToken;
            result.Items             = activityList;

            return(new OkObjectResult(result));
        }
Пример #17
0
        /// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="activityService"></param>
        /// <param name="userId">UserId</param>
        /// <param name="activity">动态</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //检查用户是否已在信息发布者的粉丝圈里面
            FollowService followService = new FollowService();

            if (followService.IsFollowed(userId, activity.UserId))
            {
                return(false);
            }
            //检查用户是否接收该动态项目
            Dictionary <string, bool> userSettings = activityService.GetActivityItemUserSettings(userId);

            if (userSettings.ContainsKey(activity.ActivityItemKey))
            {
                return(userSettings[activity.ActivityItemKey]);
            }
            else
            {
                //如果用户没有设置从默认设置获取
                ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);
                if (activityItem != null)
                {
                    return(activityItem.IsUserReceived);
                }
                else
                {
                    return(true);
                }
            }
        }
        public void SetRankAnActivityTest()
        {
            IUserService         _userService         = new UserService(_context);
            IActivityService     _activityService     = new ActivityService(_context);
            IUserActivityService _userActivityService = new UserActivityService(_context);
            ApplicationUser      user = new ApplicationUser {
                UserName = "******"
            };
            bool userSaveResult = _userService.AddUser(user);

            RecretionalActivity kayaking = new RecretionalActivity {
                ActivityName = "Kayaking"
            };

            _activityService.AddAnActivity(kayaking);
            RecretionalActivity camping = new RecretionalActivity {
                ActivityName = "Camping"
            };

            _activityService.AddAnActivity(camping);

            if (userSaveResult)
            {
                _userActivityService.ChooseAnActivity(user, kayaking);
                _userActivityService.ChooseAnActivity(user, camping);
            }

            bool setKayakingAsFiveStarRatingResult = _userActivityService.SetRankAnActivity(user, kayaking, Rating.fiveStar);
            bool setCampingAsFourStarRatingResult  = _userActivityService.SetRankAnActivity(user, camping, Rating.fourStar);

            Assert.IsTrue(setKayakingAsFiveStarRatingResult);
            Assert.IsTrue(setCampingAsFourStarRatingResult);
        }
Пример #19
0
 public UserController(PersonService personService, ActivityService activityService, PostService postService, FavoriteService favoriteService)
 {
     this.personService   = personService;
     this.activityService = activityService;
     this.postService     = postService;
     this.favoriteService = favoriteService;
 }
    public AquariumServiceTests()
    {
        // Set up configuration sources.
        var builder = new ConfigurationBuilder()
                      .SetBasePath(Directory.GetCurrentDirectory())
                      .AddJsonFile($"./config.json", optional: false)
                      .AddEnvironmentVariables();

        _config = builder.Build();

        //Set up AutoMapper
        var config = new MapperConfiguration(cfg => { cfg.AddProfile <MappingProfile>(); });

        _mapper = config.CreateMapper();

        //Set up db
        _dbAquariumContext = new DbAquariumContext(new DbContextOptionsBuilder <DbAquariumContext>()
                                                   .UseInMemoryDatabase(Guid.NewGuid().ToString() + "dbAquarium")
                                                   .Options);
        _aquariumDao = new AquariumDao(_mapper, _config, _dbAquariumContext, new NullLogger <AquariumDao>());



        //Set up service
        _activityService = new ActivityService(_config, _aquariumDao, _mapper);
        _accountService  = new AccountService(null, _config, _aquariumDao, null, null);
        _aquariumService = new AquariumService(_config,
                                               new NullLogger <AquariumService>(),
                                               _aquariumDao,
                                               _accountService,
                                               _activityService,
                                               null,
                                               null);
    }
Пример #21
0
        public async void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Pivot p = sender as Pivot;

            if (p.SelectedIndex == 0)
            {
                IsEventsLoading = true;
                Events          = await ActivityService.GetUserPerformedActivity(Developer.Login);

                IsEventsLoading = false;
            }
            else if (p.SelectedIndex == 1)
            {
                IsReposLoading = true;
                Repositories   = await RepositoryUtility.GetRepositoriesForUser(Developer.Login);

                IsReposLoading = false;
            }
            else if (p.SelectedIndex == 2)
            {
                IsFollowersLoading = true;
                Followers          = await UserUtility.GetAllFollowers(Developer.Login);

                IsFollowersLoading = false;
            }
            else if (p.SelectedIndex == 3)
            {
                IsFollowingLoading = true;
                Following          = await UserUtility.GetAllFollowing(Developer.Login);

                IsFollowingLoading = false;
            }
        }
Пример #22
0
        public void MemberJoinedActivityGet()
        {
            const string guidStr = "515b7240-3be1-43d4-8846-c0b589cd1cd2";

            var timestamp          = DateTime.UtcNow;
            var activityRepository = Substitute.For <IActivityRepository>();

            _membershipRepository.Get(new Guid(guidStr)).Returns(new MembershipUser());
            var memberJoinedActivitiesInDb = new List <Activity>
            {
                new Activity
                {
                    Type      = ActivityType.MemberJoined.ToString(),
                    Timestamp = timestamp,
                    Data      = MemberJoinedActivity.KeyUserId + "=" + guidStr
                }
            };

            var pagedJoinedActivities = new PagedList <Activity>(memberJoinedActivitiesInDb, 1, 20, 1);

            activityRepository.GetPagedGroupedActivities(1, 20).Returns(pagedJoinedActivities);

            IActivityService activityService = new ActivityService(activityRepository, _badgeRepository, _membershipRepository, _loggingService);
            var memberJoinedActivities       = activityService.GetPagedGroupedActivities(1, 20);

            Assert.IsTrue(memberJoinedActivities[0] is MemberJoinedActivity);
        }
Пример #23
0
 public PetStatusModel(SqlManager sql)
 {
     this.sql = sql;
     login    = new LoginService(this.sql);
     pet      = new PetService(this.sql);
     activity = new ActivityService(this.sql);
 }