Exemplo n.º 1
0
        public override async Task Render(MessageResult message)
        {
            await base.Render(message);

            if (taskTitle == null)
            {
                await Device.Send("Начинаем создание новой задачи.\nВведите название:");
            }
            else if (taskDescription == null)
            {
                await Device.Send("Введите описание:");
            }
            else if (date == null)
            {
                var deadlineSelection = new DateSelectionDialog();
                deadlineSelection.Completed += date =>
                {
                    this.date = date;
                };
                await OpenModal(deadlineSelection);
            }
            else if (priority == null)
            {
                var prioritySelection = new SelectPriorityDialog();
                prioritySelection.Completed += priority =>
                {
                    this.priority = priority;
                };
                await OpenModal(prioritySelection);
            }
            else
            {
                await Device.Send($"Задача создана.\nНазвание: {taskTitle}\nОписание:\n{taskDescription}");

                var id = Guid.NewGuid();



                db.Tasks.Add(new Models.PersonalTask()
                {
                    Id              = id,
                    Title           = taskTitle,
                    Description     = taskDescription,
                    CreatorDeviceId = message.DeviceId,
                    Deadline        = date.Value,
                    Priority        = priority.Value
                });

                await db.SaveChangesAsync();
                await NavigateTo(DI.Resolve(new AssignTaskForm(id)));
            }
        }
Exemplo n.º 2
0
        public override async Task Load(MessageResult message)
        {
            await base.Load(message);

            var task = await db.Tasks.FirstAsync(x => x.Id == editTaskId);

            switch (currentState)
            {
            case EditState.Watch:
                if (message.GetData <CallbackData>() is CallbackData call)
                {
                    if (call.Method == "back")
                    {
                        await NavigateTo(new MenuForm());
                    }
                    else if (call.Method == "edit-title")
                    {
                        currentState = EditState.Title;
                    }
                    else if (call.Method == "edit-description")
                    {
                        currentState = EditState.Description;
                    }
                    else if (call.Method == "responsible")
                    {
                        currentState = EditState.Responsible;
                    }
                    else if (call.Method == "deadline")
                    {
                        var deadlineSelection = new DateSelectionDialog();
                        deadlineSelection.Completed += date => {
                            task.Deadline = date;
                            db.Tasks.Update(task);
                            db.SaveChanges();
                        };
                        await OpenModal(deadlineSelection);
                    }
                    else if (call.Method == "priority")
                    {
                        var prioritySelection = new SelectPriorityDialog();
                        prioritySelection.Completed += priority => {
                            task.Priority = priority;
                            db.Tasks.Update(task);
                            db.SaveChanges();
                        };
                        await OpenModal(prioritySelection);
                    }
                }
                return;

            case EditState.Title:
                var newTitle = message.MessageText;
                task.Title = newTitle;
                db.Tasks.Update(task);
                await db.SaveChangesAsync();

                currentState = EditState.Watch;
                return;

            case EditState.Description:
                var newDescription = message.MessageText;
                task.Description = newDescription;
                db.Tasks.Update(task);
                await db.SaveChangesAsync();

                currentState = EditState.Watch;
                return;

            case EditState.Deadline:
                currentState = EditState.Watch;
                return;

            case EditState.Priority:
                currentState = EditState.Watch;
                return;

            default:
                return;
            }
        }