protected void Page_Load(object sender, EventArgs e)
        {
            TasksControllers tasks = new TasksControllers();

            ListTask.DataSource = tasks.TaskList();
            ListTask.DataBind();
        }
        public async Task <IActionResult> Update(int id, [FromBody] ListTask model)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();

                return(BadRequest(errors));
            }

            var found = await ctx.ListTasks.FindAsync(id);

            if (found != null)
            {
                found.Title     = model.Title;
                found.Desc      = model.Desc;
                found.UpdatedAt = DateTime.Now;
                found.UserId    = model.UserId;
                found.ProjectId = model.ProjectId;
                await ctx.SaveChangesAsync();

                return(Ok(found));
            }
            return(NotFound("Không tồn tại List Task"));
        }
Exemple #3
0
        public void Error_IfParametersAreNull()
        {
            var linput = new ListInput();
            var param  = new Parameters
            {
                AwsAccessKeyId     = null,
                AwsSecretAccessKey = " ",
                BucketName         = string.Empty
            };
            var opt = new ListOptions {
                FullResponse = true
            };

            async Task TestDelegate()
            {
                await ListTask.ListObjectsAsync(linput, param, opt, new CancellationToken());
            }

            Assert.That(TestDelegate,
                        Throws.TypeOf <ArgumentNullException>()
                        .With.Message.EndsWith(
                            string.Join(", ",
                                        nameof(param.AwsAccessKeyId),
                                        nameof(param.AwsSecretAccessKey),
                                        nameof(param.BucketName))));
        }
Exemple #4
0
        public int Create(ListTask newLt)
        {
            string sql = @"
            INSERT INTO listtask
            (listId, taskId, creatorId)
            VALUES
            (@ListId, @TaskId, @CreatorId);
            SELECT LAST_INSERT_ID();";

            return(_db.ExecuteScalar <int>(sql, newLt));
        }
        public bool CreateUserTask(TaskModel taskModel, int[] listsId)
        {
            try
            {
                var temp = _context.ToDoLists.Where(l => listsId.Contains(l.Id));
                if (!ListTypeHelper(listsId, taskModel, temp.ToList()))
                {
                    return(false);
                }
                Task task = new Task();

                task = _mapper.Map <TaskModel, Task>(taskModel, cfg =>
                                                     cfg.AfterMap((src, dest) =>
                {
                    dest.Importance = taskModel.Importance == null ? Importance.normal : taskModel.Importance.Value;
                }));

                _context.Tasks.Add(task);
                _context.SaveChanges();

                if (listsId == null || listsId.Length <= 0)
                {
                    ListTask listTask = new ListTask
                    {
                        ListId = 1,
                        TaskId = task.Id
                    };
                    _context.ListTasks.Add(listTask);
                    _context.SaveChanges();
                }
                else
                {
                    List <ListTask> listTasks = new List <ListTask>();
                    for (int i = 0; i < listsId.Length; i++)
                    {
                        listTasks.Add(new ListTask
                        {
                            ListId = listsId[i],
                            TaskId = task.Id
                        });
                    }
                    _context.AddRange(listTasks);
                    _context.SaveChanges();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #6
0
        public async Task <IActionResult> Update([FromBody] ListTask model, int id, ListTaskViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();
                return(BadRequest(errors));
            }

            var found = await context.ListTasks.FindAsync(id);

            if (found != null)
            {
                found.Title     = model.Title;
                found.Desc      = model.Desc;
                found.UpdatedAt = DateTime.Now;
                await context.SaveChangesAsync();

                var history = new ProjectHistory()
                {
                    ProjectId = model.ProjectId,
                    UserId    = model.UserId,
                    Content   = "Thay đổi danh sách công việc",
                    CreatedAt = DateTime.Now,
                    UpdatedAt = DateTime.Now
                };

                await context.ProjectHistories.AddAsync(history);

                await context.SaveChangesAsync();

                var FullName = await context.Users.Where(u => u.Id == model.UserId).Select(u => u.FullName).FirstAsync();

                /*==============================
                *  Get projects and projectHistory
                *  ==============================*/

                viewModel.Id        = id;
                viewModel.Title     = model.Title;
                viewModel.Desc      = model.Desc;
                viewModel.ProjectId = model.ProjectId;
                viewModel.FullName  = FullName;
                viewModel.Content   = history.Content;
                viewModel.CreatedAt = viewModel.CreatedAt;
                return(Ok(viewModel));
            }


            return(BadRequest("Không tồn tại list task"));
        }
Exemple #7
0
        public async Task <ActionResult <ListTask> > Post([FromBody] ListTask newLt)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newLt.CreatorId = userInfo.Id;
                return(Ok(_lts.Create(newLt)));
            }
            catch (Exception err)
            {
                return(BadRequest(err.Message));
            }
        }
        private void OnListTimer()
        {
            if (ListTask == null || !ListTask.Wait(0, ListTaskCancellation.Token))
            {
                return;
            }

            ListTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
            IsListing           = false;
            IsListingCancelable = true;

            CalendarList?Result = ListTaskCancellation.IsCancellationRequested ? null : ListTask.Result;

            ListTask = null;

            ParseCalendarListResult(Result);
        }
        public async Task <ActionResult> Create([FromBody] ListTask model)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();

                return(BadRequest(errors));
            }

            model.CreatedAt = DateTime.Now;
            model.UpdatedAt = DateTime.Now;
            ctx.ListTasks.Add(model);
            await ctx.SaveChangesAsync();

            return(Ok(model));
        }
Exemple #10
0
        internal string Delete(int id, string userId)
        {
            ListTask original = _repo.GetOne(id);

            if (original == null)
            {
                throw new Exception("Bad ID");
            }
            ;
            if (original.CreatorId != userId)
            {
                throw new Exception("Not your List : Access Denied");
            }
            if (_repo.Remove(id))
            {
                return("Great Success!");
            }
            return("Much Failure.");
        }
Exemple #11
0
        public void Error_IfBucketNameIsEmpty()
        {
            var linput = new ListInput();

            var param = new Parameters
            {
                AwsAccessKeyId     = "foo",
                AwsSecretAccessKey = "bar",
                BucketName         = null
            };
            var opt = new ListOptions {
                FullResponse = true
            };

            async Task TestDelegate()
            {
                await ListTask.ListObjectsAsync(linput, param, opt, new CancellationToken());
            }

            Assert.That(TestDelegate, Throws.TypeOf <ArgumentNullException>().With.Message.StartWith("Value cannot be null."));
        }
Exemple #12
0
        private void ProcessCommands(string commands)
        {
            string   commandType   = String.Join(string.Empty, commands.Split());
            ICommand command       = null;
            string   commandResult = String.Empty;

            switch (commandType)
            {
            case "register":
            case "registeruser":
                command = new RegisterCommand();
                break;

            case "login":
            case "log":
                command = new LoginCommand();
                break;

            case "logout":
                command = new LogOutCommand();
                break;

            case "addnotebook":
                command = new AddNotebookCommand();
                break;

            case "addnote":
                if (LoggedUser.Notebooks.Count == 0)
                {
                    throw new ArgumentException(Messages.MustCreateANotebook());
                }
                command = new AddNoteCommand();
                break;

            case "switchnotebook":
                command = new SwitchNotebookCommand();
                break;

            case "addtask":
                command = new AddTaskCommand();
                break;

            case "addlongtermtask":
                command = new AddLongTermTaskCommand();
                break;

            case "addsubtask":
                command = new AddSubtaskCommand();
                break;

            case "addremindertotask":
                command = new AddReminderToTaskCommand();
                break;

            case "addnotetofavourites":
                command = new AddNoteToFavouritesCommand();
                break;

            case "addnotebooktofavourites":
                command = new AddNotebookToFavouritesCommand();
                break;

            case "listall":
                command = new ListCommand();
                break;

            case "listtask":
                command = new ListTask();
                break;

            case "listnotebook":
                command = new ListNotebookCommand();
                break;

            case "listnote":
                command = new ListNoteCommand();
                break;

            case "listlongtermtask":
                command = new ListLongTermTaskCommand();
                break;

            case "listsubtask":
                command = new ListSubTaskCommand();
                break;

            case "switchlongtertask":
                command = new SwitchLongTermTaskCommand();
                break;

            case "deletetask":
                command = new DeleteTaskCommand();
                break;

            case "deletesubtask":
                command = new DeleteSubTaskCommand();
                break;

            case "clearhistory":
                command = new ClearHistoryCommand();
                break;

            case "sortallnotebooks":
                command = new SortNotebooksCommand();
                break;

            case "sortnotebook":
                command = new SortNotebookCommand();
                break;

            case "sorttasks":
                command = new SortTasksCommand();
                break;

            default:
                throw new ArgumentException("Wrong Command");
            }

            command.TakeInput();
            commandResult = command.Execute();
            Writer.WriteLine(commandResult);
        }
Exemple #13
0
 public ListTask Create(ListTask newLt)
 {
     newLt.Id = _repo.Create(newLt);
     return(newLt);
 }
Exemple #14
0
 protected override IEnumerable <ITask> Handle(ListTask request)
 {
     return(_store.List(t => true, request.PageNumber, request.PageSize));
 }