Exemplo n.º 1
0
 private void SetValues(EmployeeDTO employee)
 {
     Id     = employee.Id;
     MANR   = employee.MANR;
     Name   = employee.Name;
     Status = Statuses.FirstOrDefault(s => s.Id == employee.Status);
 }
        async Task SetData(AsanaTask task)
        {
            Task         = task;
            IsForSync    = task.IsForSync;
            Status       = Statuses.FirstOrDefault(x => x.name == task.assignee_status);
            Name         = task.name;
            Notes        = task.notes;
            IsUseDueDate = task.due_on.HasValue;
            DueDate      = task.due_on.HasValue ? task.due_on.Value : DateTime.Today;
            IsUseDueDate = task.due_on.HasValue;
            IsCompleted  = task.completed;
            ProjectId    = task.projectid;
            if (task.assigneeid > 0)
            {
                UserId = task.assigneeid;
            }

            SelectedFollowers = Followers.Where(x => task.GetFollowers().Contains(x.id)).ToList();
            OldFollowersIds   = SelectedFollowers.Select(x => x.id).ToList();


            var tags = await new StorageService().GetTagsByTask(task.id);

            OldTagsIds   = tags.Select(x => x.id).ToList();
            SelectedTags = Tags.Where(x => OldTagsIds.Contains(x.id)).ToList();
        }
Exemplo n.º 3
0
        private async void GetStatuses()
        {
            Statuses = await _serviceClient.GetOrderStatuses();

            if (Item.Status == null)
            {
                return;
            }
            Item.Status = Statuses.FirstOrDefault(x => x.Id == Item.Status.Id);
            Item.OnPropertyChanged(nameof(Item.Status));
        }
Exemplo n.º 4
0
        public AspirantSelectLists(Aspirant aspirant, AspiranturaContext context)
        {
            Statuses     = Helper.GetStatuses();
            Studyforms   = Helper.GetStudyForms();
            Specialities = Helper.GetSpecialities(context);
            Departments  = Helper.GetDepartments(context);
            Prepods      = Helper.GetPrepods(context);

            if (aspirant != null)
            {
                selectedStatus     = Statuses.FirstOrDefault(k => k.Value == (int)aspirant.StatusType);
                selectedStudyform  = Studyforms.FirstOrDefault(k => k.Value == (int)aspirant.StudyForm);
                selectedSpeciality = Specialities.FirstOrDefault(k => k.Value == aspirant.SpecialityId);  // возможно нужна проверка на null
                selectedDepartment = Departments.FirstOrDefault(k => k.Value == aspirant.DepartmentId);
                selectedPrepod     = Prepods.FirstOrDefault(k => k.Value == aspirant.PrepodId);
            }
        }
        async void LoadData()
        {
            var storageService = new StorageService();

            AddOperation();

            if (WorkspaceId == 0)
            {
                if (ProjectId.HasValue)
                {
                    var project = await storageService.Find <AsanaProject>(ProjectId.Value);

                    WorkspaceId = project.workspaceid;
                }
                else if (Id.HasValue)
                {
                    var task = await storageService.Find <AsanaTask>(Id.Value);

                    if (task == null)
                    {
                        MessageBox.Show("Task is not found");
                        NavigationManager.GoBack();
                        return;
                    }

                    WorkspaceId = task.workspaceid;
                }
                else if (ParentId.HasValue)
                {
                    var task = await storageService.Find <AsanaTask>(ParentId.Value);

                    if (task == null)
                    {
                        MessageBox.Show("Task is not found");
                        NavigationManager.GoBack();
                        return;
                    }

                    WorkspaceId = task.workspaceid;
                    ProjectId   = task.projectid;

                    CanEditProject = false;
                }
            }



            var followers = await storageService.GetUsers(WorkspaceId);

            Followers.AddRange(followers);

            AppTitle = (await storageService.Find <AsanaWorkspace>(WorkspaceId)).name;

            var tags = await storageService.GetTags(WorkspaceId);

            Tags.AddRange(tags);

            if (IsEditMode)
            {
                var task = await storageService.Find <AsanaTask>(Id.Value);


                if (task == null)
                {
                    MessageBox.Show("Task is not found");
                    NavigationManager.GoBack();
                    return;
                }

                var r = await CheckSyncStatus(task);

                if (r != null)
                {
                    task = r;
                }

                await SetData(task);


                if (task.parentId.HasValue)
                {
                    CanEditProject = false;
                }



                //      if (model.CheckInternetConnection(false))
                //      {
                //          var response =
                //await AsanaClient.SendRequest(() => new AsanaRespository().GetTask(model.Id.Value));

                //          if (AsanaClient.ProcessResponse(response))
                //          {
                //              response.Data.projectid = response.Data.projects.Any() ? response.Data.projects.First().id : 0;
                //              response.Data.assigneeid = response.Data.assignee != null ? response.Data.assignee.id : 0;

                //              SetData(response.Data);

                //              using (var db = new DbTransaction())
                //              {
                //                  db.InsertOrUpdate(response.Data);
                //                  db.Commit();
                //              }
                //          }



                //      }
            }
            else
            {
                DueDate = DateTime.Today;
            }

            var projects = await storageService.GetActiveProjects(WorkspaceId);

            Projects.Insert(0, new AsanaProject
            {
                id          = 0,
                name        = "none",
                workspaceid = WorkspaceId
            });
            Projects.AddRange(projects);



            Project = ProjectId.HasValue
                                                          ? Projects.FirstOrDefault(x => x.id == ProjectId.Value)
                                                          : Projects.FirstOrDefault(x => x.id > 0);
            if (Project != null)
            {
                OldProjectId = Project.id;
            }

            if (Project == null)
            {
                Project = Projects.FirstOrDefault(x => x.id > 0);
            }



            if (Status == null)
            {
                Status = Statuses.FirstOrDefault(x => x.name == EAsanaTaskStatus.upcoming.ToString());
            }



            var users = await storageService.GetUsers(WorkspaceId);


            Users.Insert(0, new AsanaUser()
            {
                id   = -1,
                name = "none"
            });
            Users.AddRange(users);

            User = UserId.HasValue ? Users.FirstOrDefault(x => x.id == UserId.Value) : Users.FirstOrDefault();

            if (User == null)
            {
                User = Users.FirstOrDefault();
            }



            RemoveOperation();
        }
Exemplo n.º 6
0
        private async Task GenerateList(int?statusId = null)
        {
            var allStatus = await context.Statuses.ToListAsync();

            Statuses.AddRange(allStatus.OrderBy(p => p.Name));

            Statuses.Add(DefaultStatus);
            if (!statusId.HasValue)
            {
                var defaultStats = Statuses.FirstOrDefault(p => p.Name.Equals("Assigned"));
                if (defaultStats != null)
                {
                    ActiveStatusId = defaultStats.Id;
                }
            }
            else
            {
                ActiveStatusId = statusId.Value;
            }


            IList <TicketListItemDto> ticketResult = new List <TicketListItemDto>();

            ticketResult = await ticketService.GetAllTicketsAsync(ActiveStatusId);

            if (ticketResult.Any())
            {
                TicketBody.TicketList = ticketResult;
            }

            TicketHeader.ReportedBy.Add(DefaultListItem);

            var reportedByList = await ticketService.GetAllNamesOfReportedBy();

            TicketHeader.ReportedBy.AddRange(reportedByList.Select(p => new SelectListItem
            {
                Selected = p.Equals(Filter.ReportedBy),
                Text     = p,
                Value    = p
            }).ToList());

            TicketHeader.PropertySort = TicketPropertyNames().ToList();

            TicketHeader.AssignedTo.Add(DefaultListItem);

            TicketHeader.AssignedTo.AddRange(await context.Users.Select(p => new SelectListItem
            {
                Selected = p.Id == Filter.AssignedToId,
                Text     = $"{p.FirstName} {p.LastName}",
                Value    = p.Id.ToString()
            }).ToListAsync());

            TicketHeader.CreatedBy.Add(DefaultListItem);

            TicketHeader.CreatedBy.AddRange(await context.Users.Select(p => new SelectListItem
            {
                Selected = p.Id == Filter.CreatedById,
                Text     = $"{p.FirstName} {p.LastName}",
                Value    = p.Id.ToString()
            }).ToListAsync());

            TicketHeader.Priorities.Add(DefaultListItem);
            TicketHeader.Priorities = await context.Priorities.Select(p => new SelectListItem
            {
                Selected = p.Id == Filter.PriorityId,
                Text     = p.Name,
                Value    = p.Id.ToString()
            }).ToListAsync();
        }
Exemplo n.º 7
0
        public async Task UpdateStatuses(long maxid = 0)
        {
            if (UpdatingStatuses)
            {
                return;
            }

            if (_userId == 0 || Tokens == null)
            {
                return;
            }

            UpdatingStatuses = true;

            try
            {
                var param = new Dictionary <string, object>
                {
                    { "count", 20 },
                    { "include_entities", true },
                    { "user_id", _userId },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param.Add("max_id", maxid);
                }

                var userTweets = await Tokens.Statuses.UserTimelineAsync(param);

                if (maxid == 0)
                {
                    Statuses.Clear();
                }

                foreach (var status in userTweets)
                {
                    Connecter.Instance.TweetReceive_OnCommandExecute(this,
                                                                     new TweetEventArgs(status, Tokens.UserId, new List <string> {
                        "none://"
                    }, false));

                    var id    = status.HasRetweetInformation ? status.RetweetInformation.Id : status.Id;
                    var index = Statuses.IndexOf(
                        Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) == id));
                    if (index == -1)
                    {
                        index = Statuses.IndexOf(
                            Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) < id));
                        if (index == -1)
                        {
                            Statuses.Add(status);
                        }
                        else
                        {
                            Statuses.Insert(index, status);
                        }
                    }
                }
            }
            catch
            {
                if (maxid == 0)
                {
                    Statuses.Clear();
                }

                UpdatingStatuses = false;
                return;
            }

            UpdatingStatuses = false;
        }
Exemplo n.º 8
0
        public async Task UpdateStatuses(long maxid = 0, bool clear = true)
        {
            if (UpdatingStatusSearch)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(_statusSearchWords) || Tokens == null)
            {
                return;
            }

            UpdatingStatusSearch = true;

            if (maxid == 0 && clear)
            {
                Statuses.Clear();
            }

            IEnumerable <Status> search;

            if (SettingService.Setting.UseOfficialApi &&
                TwitterConnectionHelper.OfficialConsumerKeyList.Contains(Tokens.ConsumerKey))
            {
                var param = new Dictionary <string, object>
                {
                    { "q", _statusSearchWords },
                    { "count", 20 },
                    { "result_type", "recent" },
                    { "modules", "status" },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param["q"] = param["q"] + " max_id:" + maxid;
                }

                try
                {
                    var res = await Tokens.TwitterTokens.SendRequestAsync(CoreTweet.MethodType.Get,
                                                                          "https://api.twitter.com/1.1/search/universal.json", param);

                    var json = await res.Source.Content.ReadAsStringAsync();

                    var jsonObject = JObject.Parse(json);
                    var modules    = jsonObject["modules"].Children <JObject>();

                    var tweets = new List <CoreTweet.Status>();
                    foreach (var status in modules)
                    {
                        foreach (var prop in status.Properties())
                        {
                            if (prop.Name == "status")
                            {
                                tweets.Add(
                                    CoreTweet.Core.CoreBase.Convert <CoreTweet.Status>(
                                        JsonConvert.SerializeObject(status["status"]["data"])));
                            }
                        }
                    }

                    search = tweets.Select(x => new Status(x));
                }
                catch
                {
                    if (maxid == 0 && clear)
                    {
                        Statuses.Clear();
                    }

                    UpdatingStatusSearch = false;
                    return;
                }
            }
            else
            {
                var param = new Dictionary <string, object>
                {
                    { "count", 20 },
                    { "include_entities", true },
                    { "q", _statusSearchWords },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param.Add("max_id", maxid);
                }

                try
                {
                    search = await Tokens.Search.TweetsAsync(param);
                }
                catch
                {
                    if (maxid == 0 && clear)
                    {
                        Statuses.Clear();
                    }

                    UpdatingStatusSearch = false;
                    return;
                }
            }

            if (maxid == 0 && clear)
            {
                Statuses.Clear();
            }

            foreach (var status in search)
            {
                Connecter.Instance.TweetReceive_OnCommandExecute(this,
                                                                 new TweetEventArgs(status, Tokens.UserId, new List <string> {
                    "none://"
                }, false));

                var id    = status.HasRetweetInformation ? status.RetweetInformation.Id : status.Id;
                var index = Statuses.IndexOf(
                    Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) == id));
                if (index == -1)
                {
                    index = Statuses.IndexOf(
                        Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) < id));
                    if (index == -1)
                    {
                        Statuses.Add(status);
                    }
                    else
                    {
                        Statuses.Insert(index, status);
                    }
                }
            }

            UpdatingStatusSearch = false;
        }