Esempio n. 1
0
        public ActivityDetailsViewModel(int activityId, string groupId)
        {
            _activityId = activityId;
            _groupId    = groupId;
            var      errCode        = 0;
            var      errMsg         = string.Empty;
            DateTime serverDateTime = DateTime.Now;

            AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher,
                                        () =>
            {
                AntSdkGetGroupActivityDetailsInput input = new AntSdkGetGroupActivityDetailsInput
                {
                    userId     = AntSdkService.AntSdkCurrentUserInfo.userId,
                    activityId = activityId,
                    groupId    = groupId
                };
                AntSdkQuerySystemDateOuput serverResult = AntSdkService.AntSdkGetCurrentSysTime(ref errCode,
                                                                                                ref errMsg);

                if (serverResult != null)
                {
                    serverDateTime = PublicTalkMothed.ConvertStringToDateTime(serverResult.systemCurrentTime);
                }
                var output = AntSdkService.GetActivityInfo(input, ref errCode, ref errMsg);
                return(output);
            },
                                        (ex, datas) =>
            {
                if (datas != null)
                {
                    ActivityTitle = datas.theme;
                    if (!string.IsNullOrEmpty(datas.picture))
                    {
                        try
                        {
                            BitmapImage image = new BitmapImage();

                            image.BeginInit();

                            image.UriSource = new System.Uri(datas.picture);

                            image.DecodePixelWidth = 800;

                            image.EndInit();

                            ActivityThemePic = image;
                        }
                        catch (Exception e)
                        {
                            LogHelper.WriteError("[ActivityDetailsViewModel_ImageOnLoad]:" + e.Message + e.StackTrace + e.Source);
                        }
                    }
                    ActivityAddress   = datas.address;
                    ActivityIntroduce = datas.description;
                    latitude          = datas.latitude;
                    longitude         = datas.longitude;
                    Console.Out.WriteLine("");
                    var startTime = DateTime.Now;
                    var endTime   = DateTime.Now.AddMinutes(30);
                    if (!string.IsNullOrEmpty(datas.startTime) && !string.IsNullOrEmpty(datas.endTime))
                    {
                        startTime         = Convert.ToDateTime(datas.startTime);
                        endTime           = Convert.ToDateTime(datas.endTime);
                        TimeSpan timeSpan = endTime - startTime;
                        if (endTime.Year - startTime.Year == 0 && endTime.Day - startTime.Day == 0)
                        {
                            ActivityDateTime = startTime.ToString("yyyy-MM-dd HH:mm") + "-" +
                                               endTime.ToString("HH:mm");
                        }
                        else
                        {
                            ActivityDateTime = startTime.ToString("yyyy-MM-dd HH:mm") + "   " +
                                               endTime.ToString("yyyy-MM-dd HH:mm");
                        }
                    }
                    else
                    {
                        ActivityDateTime = startTime.ToString("yyyy-MM-dd HH:mm") + "-" +
                                           endTime.ToString("HH:mm");
                    }
                    ParticipatorsCount = datas.voteCount ?? 0;
                    if (datas.activityStatus == 1)
                    {
                        if (!datas.voteFlag)
                        {
                            if (DateTime.Compare(startTime, serverDateTime) <= 0)
                            {
                                ActivityStateContent   = "已开始";
                                IsParticipatedActivity = false;
                            }
                            else
                            {
                                ActivityStateContent   = "报名参加";
                                IsParticipatedActivity = true;
                            }
                        }
                        else
                        {
                            ActivityStateContent   = "已报名";
                            IsParticipatedActivity = false;
                        }
                    }
                    else
                    {
                        ActivityStateContent   = "已结束";
                        IsParticipatedActivity = false;
                    }
                    LoadActivityParticipators();
                }
            });
        }