コード例 #1
0
        public async Task <IActionResult> Update()
        {
            var model = await _client.Get <UserProfileBL>($"api/profile");

            var viewmodel = new ProfileViewModel()
            {
                Email      = model.Email,
                FamilyName = model.FamilyName,
                Name       = model.Name,
                Patronymic = model.Patronymic,
                telephone  = model.Telephone,
                HasPhoto   = (!string.IsNullOrWhiteSpace(model.Photo))
            };

            return(View(viewmodel));
        }
コード例 #2
0
        public async Task <IActionResult> Index()
        {
            var model    = new FriendsViewModel();
            var requests = await _client.Get <IEnumerable <UserFriendBL> >("api/friendrequests");

            model.friendRequests = requests.Select(fr => new FriendViewModel()
            {
                FriendId   = fr.FriendId,
                AddDate    = fr.AddDate,
                FamilyName = fr.Friend.FamilyName,
                Name       = fr.Friend.Name,
                UserName   = fr.Friend.UserName,
                Photo      = fr.Friend.Photo
            }).ToList();

            var friends = await _client.Get <IEnumerable <UserFriendBL> >("api/friends");

            model.friends = friends.Select(fr => new FriendViewModel()
            {
                AddDate    = fr.AddDate,
                FriendId   = fr.FriendId,
                FamilyName = fr.Friend.FamilyName,
                Name       = fr.Friend.Name,
                UserName   = fr.Friend.UserName,
                Photo      = fr.Friend.Photo
            }).ToList();

            var editRequests = await _taskClient.Get <IEnumerable <TaskEditGrantsBL> >("api/mytaskfriendgrant/list");

            model.editRequests = editRequests.Select(er => new FriendEditRequestViewModel()
            {
                TaskId     = er.TaskId,
                FriendId   = er.FriendId,
                FamilyName = friends.FirstOrDefault(fr => fr.FriendId == er.FriendId).Friend.FamilyName,
                Name       = friends.FirstOrDefault(fr => fr.FriendId == er.FriendId).Friend.Name,
                UserName   = friends.FirstOrDefault(fr => fr.FriendId == er.FriendId).Friend.UserName,
                Photo      = friends.FirstOrDefault(fr => fr.FriendId == er.FriendId).Friend.Photo,
                AddDate    = er.date
            }).ToList();

            return(View(model));
        }
コード例 #3
0
        public async Task <IEnumerable <TaskModelBL> > GetAll(string FriendId)
        {
            var token = await _tokenService.GetIdentityToken(new LoginViewModel()
            {
                UserName = "******",
                Password = "******"
            });

            if (!token.Success)
            {
                throw new Exception(token.Error);
            }

            var friends = await _client.Get <IEnumerable <UserFriendBL> >("api/friends");

            IEnumerable <MyTask> list = null;

            if (HttpContextExtensions.IsAdmin(_httpcontext))
            {
                list = context.MyTasks;
            }
            else
            {
                var idlist = context.UsersInTasks.Where(u => u.UserId == FriendId).Select(u => u.MyTaskId);
                list = context.MyTasks.Where(t => idlist.Contains(t.Id));
            }

            return(list.Select(task => new TaskModelBL()
            {
                Id = task.Id,
                Name = task.Name,
                StartDate = task.StartDate,
                TargetDate = task.TargetDate,
                EndDate = task.EndDate,
                Details = task.Details,
                IsRepeating = task.IsRepeating,
                TaskСategoryId = task.TaskСategoryId,
                TaskPriorityId = task.TaskPriorityId,
                ParentTaskId = task.ParentTaskId,
                files = null
            }));
        }
コード例 #4
0
        public async Task <IActionResult> Update(int id)
        {
            TaskModelBL task = await _client.Get <TaskModelBL>("api/mytask/details/" + id.ToString());

            if (task == null)
            {
                return(NotFound());
            }
            MyTaskViewModel viewModel = new MyTaskViewModel
            {
                Id             = task.Id,
                Name           = task.Name,
                StartDate      = task.StartDate,
                TargetDate     = task.TargetDate,
                Details        = task.Details,
                IsRepeating    = task.IsRepeating,
                TaskСategoryId = task.TaskСategoryId,
                TaskPriorityId = task.TaskPriorityId,
                Multiplier     = task.Multiplier,
                PeriodCode     = task.PeriodCode,
                ParentTaskId   = task.ParentTaskId,
                TaskEditGrant  = task.EditGrant,
                IsFriendTask   = task.IsFriendTask
            };

            viewModel.files = new List <FileInfoViewModel>();
            foreach (FileModelBL fl in task.files)
            {
                viewModel.files.Add(new FileInfoViewModel()
                {
                    Id       = fl.Id,
                    FileName = fl.FileName
                });
            }

            TaskTagModelBL taskTag = await _client.Get <TaskTagModelBL>("api/tasktag/details/" + id.ToString());

            if (taskTag != null && task.Tags != null)
            {
                viewModel.Tags = new List <TagInfoViewModel>();
                foreach (TaskTagModelBL fl in task.Tags)
                {
                    viewModel.Tags.Add(new TagInfoViewModel()
                    {
                        Id   = fl.Id,
                        Name = fl.Name
                    });
                }
            }

            List <PeriodTypeModelBL> periodTypes = await _client.Get <List <PeriodTypeModelBL> >("api/periodtype");

            List <TaskCategoryModelBL> categories = await _client.Get <List <TaskCategoryModelBL> >("api/taskcategory");

            List <PriorityModelBL> priorities = await _client.Get <List <PriorityModelBL> >("api/priority");

            List <TaskModelBL> tasks = await _client.Get <List <TaskModelBL> >("api/mytask/list");

            viewModel.SubTasks = tasks.Where(t => t.ParentTaskId == task.Id)?.ToList();

            IEnumerable <UserFriendBL> friends = await _identityClient.Get <List <UserFriendBL> >("api/friends");

            IEnumerable <string> UserIds = task.UserIds;

            ViewBag.friendslist = friends.Where(fr => UserIds.Any(uid => uid == fr.UserId)).Select(f => f.Friend).ToList();

            categories.Insert(0, new TaskCategoryModelBL {
                Name = "", Id = 0
            });
            priorities.Insert(0, new PriorityModelBL {
                Name = "", Id = 0
            });


            ViewBag.Repeat     = new SelectList(periodTypes, "Id", "Name");
            ViewBag.Categories = new SelectList(categories, "Id", "Name");
            ViewBag.Priorities = new SelectList(priorities, "Id", "Name");

            return(View(viewModel));
        }