Beispiel #1
0
 public TaskVm(TodolistModel todolistModel)
 {
     TodolistId      = todolistModel.TodolistId;
     TaskDescription = todolistModel.TaskDescription;
     EnrollmentDate  = todolistModel.EnrollmentDate;
     Approved        = todolistModel.Approved;
 }
 private void ValidateList(TodolistModel model)
 {
     if (model == null || string.IsNullOrEmpty(model.Title))
     {
         throw new ArgumentNullException("Invalid TODO list title");
     }
 }
        public HttpResponseMessage CreateList(TodolistModel model,
                                              [ValueProvider(typeof(HeaderValueProviderFactory <string>))]
                                              string accessToken)
        {
            return(this.ExecuteOperationAndHandleExceptions(() =>
            {
                var context = new TasksManagerDbContext();
                var meUser = this.GetUserByAccessToken(accessToken, context);
                this.ValidateList(model);

                var listEntity = model.ToEntity();
                listEntity.Owner = meUser;
                meUser.TodoLists.Add(listEntity);
                context.SaveChanges();

                var responseModel = new ListCreatedModel()
                {
                    Id = listEntity.Id,
                    Owner = meUser.Username
                };
                var response = this.Request.CreateResponse(HttpStatusCode.Created, responseModel);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { listId = listEntity.Id }));
                return response;
            }));
        }
        public TaskVm Get(int id)
        {
            TodolistModel todolist = _taskRepository.Get(id);
            TaskVm        taskVm   = new TaskVm(todolist);

            return(taskVm);
        }
        public void Edit(TaskInput taskInput)
        {
            TodolistModel todolistToUpdate = _taskRepository.Get(taskInput.TodolistId);

            todolistToUpdate.TaskDescription = taskInput.TaskDescription;
            todolistToUpdate.Approved        = taskInput.Approved;
            _taskRepository.Save();
        }
        public void Add(TaskInput taskInput)
        {
            TodolistModel todolist = new TodolistModel();

            todolist.EnrollmentDate  = DateTime.Now;
            todolist.TaskDescription = taskInput.TaskDescription;
            _taskRepository.Add(todolist);
        }
        public TodolistModel AddTodo(TodolistModel newTodolist, string login)
        {
            var todolist = TDconverter.GetEntityByModel(newTodolist);

            _applicationContext.Users.Include(t => t.ToDoLists)
            .FirstOrDefault(u => u.Login == login).ToDoLists.Add(todolist);

            _applicationContext.SaveChanges();
            return(newTodolist);
        }
Beispiel #8
0
        internal static void CreateNewTodosList(string title, IEnumerable <TodoViewModel> todos)
        {
            var listModel = new TodolistModel()
            {
                Title = title,
                Todos = todos.Select(t => new TodoModel()
                {
                    Text = t.Text
                })
            };

            var headers = new Dictionary <string, string>();

            headers["X-accessToken"] = AccessToken;

            var httpRequester = new HttpRequester(BaseServicesUrl);

            var response =
                httpRequester.Post <ListCreatedModel>("lists", listModel, headers);
        }
        public TodolistModel Edit(int id, TodolistModel todolist)
        {
            var updatedTodo = _applicationContext.ToDoLists.Include(x => x.Tags).FirstOrDefault(t => t.Id == id);

            if (updatedTodo == null)
            {
                return(null);
            }

            updatedTodo.Description = string.IsNullOrEmpty(todolist.Description)
                ? updatedTodo.Description : todolist.Description;
            updatedTodo.Name = string.IsNullOrEmpty(todolist.Name)
                ? updatedTodo.Name : todolist.Name;
            updatedTodo.Date = string.IsNullOrEmpty(todolist.Date.ToShortDateString())
                ? updatedTodo.Date : todolist.Date;
            updatedTodo.Tags = todolist.Tags == null
                ? updatedTodo.Tags : todolist.Tags;

            _applicationContext.SaveChanges();
            return(todolist);
        }
 public void Remove(TodolistModel todolist)
 {
     _dbContext.Todolists.Remove(todolist);
     _dbContext.SaveChanges();
 }
 public void Add(TodolistModel todolist)
 {
     _dbContext.Todolists.Add(todolist);
     _dbContext.SaveChanges();
 }
        public void Remove(int id)
        {
            TodolistModel todolist = _taskRepository.Get(id);

            _taskRepository.Remove(todolist);
        }
 public TodolistModel Edit(int id, [FromBody] TodolistModel todolist)
 {
     return(_ITodolist.Edit(id, todolist));
 }
 public TodolistModel Post([FromBody] TodolistModel todolist)
 {
     return(_ITodolist.AddTodo(todolist, User.Identity.Name));
 }