public async Task <IActionResult> AddOrEditToDoItem(ToDoItemViewModel viewModel) { var model = new ToDoItemModel { ManagedCode = viewModel.ManagedCode, Title = viewModel.Title, Id = viewModel.Id, Account = new AccountModel { AccountId = Context.CurrentAccount.AccountId }, CompleteOn = DateTimeUtilities.ParseFromString(viewModel.CompleteOn).Value, Priority = viewModel.Priority.ToEnum <ToDoItemPriority>(), Status = viewModel.Status.ToEnum <ToDoItemStatus>() }; if (string.IsNullOrWhiteSpace(model.Title)) { return(BadRequest(Context.GetStringResource("TitleCannotEmpty", StringResourceType.DashboardPage))); } if (model.CompleteOn < DateTime.Now) { return(BadRequest(Context.GetStringResource("CompleteOnError", StringResourceType.DashboardPage))); } var result = await EzTask.ToDoList.Save(model); return(Json(result)); }
public void AddItem( Guid listId, ToDoItemModel toDoItemModel) { var list = ToDoLists.FirstOrDefault(x => x.Id == listId); list.AddItem(toDoItemModel); }
internal ToDoItem( Guid listId, ToDoItemModel todoItemModel) : this() { ListId = listId; Update(todoItemModel); }
public ActionResult <ToDoItemModel> Save([FromBody] ToDoItemModel item) { item.Id = items.Max(i => i.Id) + 1; items.Add(item); // return CreatedAtAction(nameof(GetById), new { id = item.Id }, item); return(item); // return Ok(item); }
public IActionResult Complete(int id) { var toDoItem = _repository.GetById <ToDoItem>(id); toDoItem.MarkComplete(); _repository.Update(toDoItem); return(Ok(ToDoItemModel.FromToDoItem(toDoItem))); }
/// <summary> /// creates a To-do item /// </summary> /// <param name="todoItem">ToDoItemModel - the To-do item to create</param> /// <returns>int - 1 if successful</returns> public int create(ToDoItemModel todoItem) { todosList.Add(todoItem); writeToFile(filePath); _logger.LogInformation($"Context.create(): To-do created"); return(1); }
public void UpdateItem( Guid listId, Guid itemId, ToDoItemModel toDoItemModel) { var list = ToDoLists.FirstOrDefault(x => x.Id == listId); var item = list.Items.FirstOrDefault(x => x.Id == itemId); item.Update(toDoItemModel); }
/// <summary> /// updates a To-do item /// </summary> /// <param name="todoItem">ToDoItemModel - the To-do item to update</param> /// <returns>int - 1 if successful</returns> public int update(ToDoItemModel todoItem) { todoItem.lastModified = DateTime.Now; var result = _todosContext.update(todoItem); _logger.LogInformation($"TodosRepository.update(): To-do updated"); return(result); }
/// <summary> /// creates a To-do item /// </summary> /// <param name="todoItem">ToDoItemModel - the To-do item to create</param> /// <returns>int - 1 if successful</returns> public int add(ToDoItemModel todoItemModel) { todoItemModel.id = Guid.NewGuid(); todoItemModel.lastModified = DateTime.Now; var result = _todosContext.create(todoItemModel); _logger.LogInformation($"TodosRepository.add(): To-do created"); return(result); }
internal static ToDoItem NewToDoItem(Api api, ToDoItemModel model) { if (model.Assignment != null) { return(new AssignmentToDoItem(api, model)); } else { return(new QuizToDoItem(api, model)); } }
public void Update(ToDoItemModel todoItemModel) { todoItemModel.Validate(); LastModifiedDate = DateTime.UtcNow; Title = todoItemModel.Title; Description = todoItemModel.Description; Priority = todoItemModel.Priority; State = todoItemModel.State; }
public IActionResult Post([FromBody] ToDoItemModel item) { var todoItem = new ToDoItem() { Title = item.Title, Description = item.Description }; _repository.Add(todoItem); return(Ok(ToDoItemModel.FromToDoItem(todoItem))); }
public async Task <ToDoItemModel> AddItemAsync(ToDoItemModel item) { var newEntity = Mapper.Map <TodoItemEntity>(item); newEntity.Operation = ClientShared.LocalData.Sync.SyncOperation.Insert; var tracker = toDoDataContext.Todos.Add(newEntity); var val = await toDoDataContext.SaveChangesAsync(); return(tracker.Entity); }
public void Update(ToDoItemModel item) { var foundItem = _repository.GetByPredicate(i => i.Id == item.Id).First(); foundItem.Header = item.Header; foundItem.Notes = item.Notes; foundItem.Date = item.Date; foundItem.Deadline = item.Deadline; foundItem.CompleteDate = item.CompleteDay; _repository.SaveChanges(); }
public async Task <IActionResult> GetTodo([FromRoute] Guid id) { ToDoItemModel toDoItemModel = await _dbContext.TodoItemModels .FirstOrDefaultAsync(x => x.Id == id); if (toDoItemModel == null) { return(NotFound("ToDo item not found")); } return(Ok(toDoItemModel)); }
public async Task <IActionResult> Create([Bind("ToDoItemId,Description,ExpectedDate,Done,UserId")] ToDoItemModel toDoItem) { if (ModelState.IsValid) { toDoItem.UserId = TempData["userId"] as string; var response = await _toDoListService.InsertToDoItem(toDoItem); return(RedirectToAction(nameof(ToDoListLogged))); } return(View(toDoItem)); }
// Note - The Xamarin.Forms Previewer requires a default, parameterless constructor to render a page. public ItemDetailPage() { InitializeComponent(); var item = new ToDoItemModel { Title = "Item 1", Description = "This is an item description." }; viewModel = new ItemDetailViewModel(Navigation, item); BindingContext = viewModel; }
private protected ToDoItem(Api api, ToDoItemModel model) { _api = api; Type = model.Type.ToApiRepresentedEnum <ToDoType>() .Expect(() => new BadApiStateException($"ToDoItem.Type was an unexpected value: {model.Type}")); ContextId = model.ContextType.ToLowerInvariant() switch { "course" => new QualifiedId(model.CourseId.Expect(), ContextType.Course), "group" => new QualifiedId(model.GroupId.Expect(), ContextType.Group), _ => throw new BadApiStateException($"ToDoItemModel.ContextType was an unexpected value: {model.ContextType}") }; IgnoreUrl = model.IgnoreUrl; PermanentIgnoreUrl = model.PermanentIgnoreUrl; }
public static ToDoItem FromModelToEntity(ToDoItemModel model) { return(new ToDoItem { Created = model.Created, Id = model.Id, Title = model.Title, User = model.User, Description = model.Description, IsDone = model.IsDone, FinishedDate = model.FinishedDate }); }
public async Task <ToDoItemModel> AddItemAsync(ToDoItemModel item) { if (item == null) { throw new Exception("Cannot send null to backend"); } var serializedItem = JsonConvert.SerializeObject(item); var response = await client.PostAsync($"api/Item/AddNewTodoItem", new StringContent(serializedItem, Encoding.UTF8, "application/json")); return(await ProcessResponse(response)); }
/// <summary> /// updates a To-do item /// </summary> /// <param name="todoItem">ToDoItemModel - the To-do item to update</param> /// <returns>int - 1 if successful</returns> public int update(ToDoItemModel todoItem) { ToDoItemModel removableTodo = todosList.First(todo => todo.id == todoItem.id); todosList.Remove(removableTodo); todosList.Add(todoItem); writeToFile(filePath); _logger.LogInformation($"Context.update(): To-do updated"); return(1); }
public async Task <IActionResult> PostTodo([FromBody] string toDoName) { if (string.IsNullOrEmpty(toDoName)) { return(BadRequest("Name should not be empty")); } var toDoItemModel = new ToDoItemModel(toDoName); await _dbContext.AddAsync(toDoItemModel); await _dbContext.SaveChangesAsync(); return(Created($"todos/{toDoItemModel.Id}", toDoItemModel.Id)); }
public ActionResult <ToDoItemModel> Update(int id, [FromBody] ToDoItemModel item) { var todo = items.FirstOrDefault(i => i.Id == id); if (todo == null) { return(NotFound()); } todo.Title = item.Title; todo.Description = item.Description; todo.Completed = item.Completed; // return(todo); }
// When page is navigated to set data context to selected item in list protected override void OnNavigatedTo(NavigationEventArgs e) { if (DataContext == null) { //string selectedIndex = ""; if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex)) { DataContext = App.ViewModel.GetItem(selectedIndex); selectedTodoItem = App.ViewModel.GetItem(selectedIndex); //int index = int.Parse(selectedIndex); //DataContext = App.ViewModel.Items[index]; } } }
public void Add(ToDoItemModel item) { var addingItem = new ToDoItem { Header = item.Header, Notes = item.Notes, Date = item.Date, Deadline = item.Deadline, CompleteDate = item.CompleteDay, UserId = _userId, ProjectId = item.ProjectId }; item.Id = _repository.Add(addingItem) ? addingItem.Id : -1; }
public static ToDoTask ToOrmEntity(this ToDoItemModel toDoItem) { if (ReferenceEquals(toDoItem, null)) { return(null); } return(new ToDoTask { UserId = toDoItem.UserId, IsCompleted = toDoItem.IsCompleted, Name = toDoItem.ToDoId != 0 ? toDoItem.Name.GetName(true) + toDoItem.ToDoId : toDoItem.Name }); }
protected static ToDoItemView GetItemView(ToDoItemModel item) { return(new ToDoItemView { Id = item.Id, Header = item.Header, Notes = item.Notes, Date = item.Date, Deadline = item.Deadline, CompleteDay = item.CompleteDay, ProjectId = item.ProjectId, ProjectName = item.ProjectName, Timer = item.Timer }); }
public async Task <IActionResult> Incomplete([FromRoute] Guid id) { ToDoItemModel toDoItemModel = await _dbContext.TodoItemModels .FirstOrDefaultAsync(x => x.Id == id); if (toDoItemModel == null) { return(NotFound("ToDo item not found")); } toDoItemModel.SetIncomplete(); await _dbContext.SaveChangesAsync(); return(Ok()); }
public static async Task DeleteToDoItem(ToDoItemModel toDoDelete) { try { await using var toDoContext = new ToDoContext(); toDoContext.Remove(toDoDelete); await toDoContext.SaveChangesAsync(); PostToDoItem(toDoContext); } catch (Exception ex) { //Handle exception - Typically I use a service like rollbar Debug.WriteLine(ex); } }
public async Task <HttpResponseMessage> AddToDoItemAsync(ToDoItemModel toDoItem) { toDoItem.Name += "," + Guid.NewGuid(); var response = await todoService.CreateItemAsync(toDoItem); if (response.IsSuccessStatusCode) { dbEntities.ToDoTask.Add(toDoItem.ToOrmEntity()); dbEntities.SaveChanges(); isSync = false; } return(response); }