public async Task <IActionResult> Edit(Guid id, [Bind("Id,Title,Completed,Color")] ToDoItemViewModel toDoItem) { if (id != toDoItem.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _toDo.EditAsync(new Item <Guid, string> { Id = toDoItem.Id, Color = toDoItem.Color, Title = toDoItem.Title, IsCompleted = toDoItem.IsCompleted }); } catch (DbUpdateConcurrencyException) { if (!ToDoItemExists(toDoItem.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(toDoItem)); }
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 async Task<IActionResult> Create(ToDoItemViewModel toDoItem) { if (ModelState.IsValid) // if the form is valid { try // try creating a new item { using (var context = new ToDoListDBContext()) { var newItem = new ToDoItem() // create new item from our ViewModel { Finished = false, Title = toDoItem.Title, UserId = toDoItem.UserId }; //add new item to the database context.ToDoItem.Add(newItem); await context.SaveChangesAsync(); } } catch(Exception e) // if something went wrong { return RedirectToAction("error", "home", new { error = e.Message }); // return error page } } return RedirectToAction("list","account", new { userid = toDoItem.UserId }); }
public async Task <IActionResult> GenerateAddOrEditTodoItemForm(int itemId = 0) { var model = new ToDoItemViewModel { AccountId = Context.CurrentAccount.AccountId }; if (itemId > 0) { var result = await EzTask.ToDoList.GetTodoItem(itemId); if (result.Status == ActionStatus.Ok) { model.CompleteOn = result.Data.CompleteOn.ToDateString(); model.Status = result.Data.Status.ToInt16 <ToDoItemStatus>(); model.Priority = result.Data.Priority.ToInt16 <ToDoItemPriority>(); model.Id = result.Data.Id; model.Title = result.Data.Title; model.ManagedCode = result.Data.ManagedCode; } else { return(NotFound(Context.GetStringResource("ItemNotExist", StringResourceType.DashboardPage))); } } model.PriorityList = StaticResources.BuildToDoItemPrioritySelectList(model.Priority); model.StatusList = StaticResources.BuildToDoItemStatusSelectList(model.Status); return(PartialView("_CreateOrEditTotoItem", model)); }
//metoda prin care se adauga un ToDo in lista din memorie si se scrie din nou lista in fisierul text public void Adauga(ToDoItemViewModel item) { //la adaugarea unui item se asigneaza un ID nou unic item.ID = currentToDos.Count + 1; currentToDos.Add(item); WriteItemsAsJson(); }
private void SetBindings() { var todo = new ToDoItemViewModel { Title = "I must learn to type", Priority = 3 }; var titleBinding = new Binding("Title") { Source = todo }; TitleTextBox.SetBinding(TextBox.TextProperty, titleBinding); var priorityBinding = new Binding("Priority") { Source = todo }; PrioritySlider.SetBinding(Slider.ValueProperty, priorityBinding); var blockBinding = new Binding("PriorityAsString") { Source = todo }; PriorityBlock.SetBinding(TextBlock.TextProperty, blockBinding); }
public void EditItem(ToDoItemViewModel editItem) { _editItem = editItem; // find the edit and static text controls var container = _todoList.ItemContainerGenerator.ContainerFromItem(editItem); _taskTextEdit = FindNamedDescendant <TextBox>(container, "taskTextEdit"); _taskText = FindNamedDescendant <TextBlock>(container, "taskText"); // store the original text to allow undo _originalText = _taskTextEdit.Text; EditFieldVisible(true); // set the caret position to the end of the text field _taskTextEdit.Focus(); _taskTextEdit.Select(_originalText.Length, 0); _taskTextEdit.LostFocus += TaskTextEdit_LostFocus; // fade out all other items ((FrameworkElement)_todoList.ItemContainerGenerator.ContainerFromItem(_editItem)).Opacity = 1; var elements = _todoItems.Where(i => i != _editItem) .Select(i => _todoList.ItemContainerGenerator.ContainerFromItem(i)) .Cast <FrameworkElement>(); foreach (var el in elements) { el.Animate(1.0, 0.7, FrameworkElement.OpacityProperty, 800, 0); } }
private void onClickTickEvent(object sender, RoutedEventArgs e) { using (var db = new SQLiteConnection(dbPath)) { FrameworkElement fe = sender as FrameworkElement; ToDoItemViewModel tappedItem = fe.DataContext as ToDoItemViewModel; List <Person> existing = db.Query <Person>("select * from Person where Id = " + tappedItem.Text3).ToList(); if (existing != null) { //existing.FirstName = Fname.Text; if (existing[0].isFav == 0) { existing[0].isFav = 1; MessageBox.Show("Added to Fav."); } else { existing[0].isFav = 0; MessageBox.Show("Removed from Fav."); } db.RunInTransaction(() => { db.Update(existing[0]); }); } } }
private void ScrollViewer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Debug.WriteLine("scrollViewer_MouseLeftButtonUp"); if (!IsActive) { return; } // hide the pull down item by locating it off screen _pullDownItem.VerticalOffset = -ToDoItemHeight; // if the list was pulled down far enough, add a new item if (_distance > ToDoItemHeight) { var newItem = new ToDoItemViewModel(""); _todoItems.Insert(0, newItem); // when the new item has been rendered, use the edit interaction to place the UI // into edit mode _todoList.InvokeOnNextLayoutUpdated(() => _editInteraction.EditItem(newItem)); } IsActive = false; _effectPlayed = false; }
/// <summary> /// Updates a todo. /// </summary> /// <param name="item">The todo to update.</param> public void UpdateItem(ToDoItemViewModel item) { if (item.ToDoId != 0) //!!! { httpClient.PutAsJsonAsync(serviceApiUrl + UpdateUrl, item) .Result.EnsureSuccessStatusCode(); } }
/// <summary> /// Updates a todo. /// </summary> /// <param name="item">The todo to update.</param> public void UpdateItem(ToDoItemViewModel item) { repository.Update(item.ToToDoDal()); listOfChanges.RemoveAll(i => i.ToDo.ToDoId == item.ToDoId && i.Operation != Operation.Create); listOfChanges.Add(new Message(item, Operation.Update)); }
/// <summary> /// Creates a todo. UserId is taken from the model. /// </summary> /// <param name="item">The todo to create.</param> public async Task <object> CreateItem(ToDoItemViewModel item) { HttpResponseMessage response = await httpClient.PostAsJsonAsync(serviceApiUrl + CreateUrl, item); object responseBody = await response.Content.ReadAsAsync <object>(); return(responseBody); }
public void UpdateItem(ToDoItemViewModel toDo) { var temp = ToDoItems.FirstOrDefault(a => a.item.UserId == toDo.UserId); ToDoItems.Add(new ToDoToServer { item = temp.item, MessageType = MessageType.UpDate }); JSONWorker.Add(ToDoItems); }
/// <summary> /// !!!!!!!!!!! /// </summary> /// <param name="item"></param> public void UpdateItem(ToDoItemViewModel item) { var temp = db.Tasks.Single(t => t.Id == item.Id); temp.IsCompleted = item.IsCompleted; temp.IsChanged = true; Update(temp); SyncService.AddToUpdateQueue(temp); }
// we can handle/transform result here - pack into ViewModel public async Task ReturnResultToUIAsync(string user, bool result, string message = "") { var model = new ToDoItemViewModel() { Result = result, Message = message }; await _hubContext.Clients.Client(user).SendAsync("ToDoResult", model).ConfigureAwait(false); }
public async Task ReturnResultToUIAsync(string user, List <ToDoItem> items) { var model = new ToDoItemViewModel() { Result = true, Items = items }; await _hubContext.Clients.Client(user).SendAsync("ToDoResult", model).ConfigureAwait(false); }
/// <summary> /// Creates a todo. UserId is taken from the model. /// </summary> /// <param name="item">The todo to create.</param> public void CreateItem(ToDoItemViewModel item) { var toDo = repository.Create(item.ToToDoDal()); idPull.Add(new IdInfo { DbId = toDo.Id }); listOfChanges.Add(new Message(toDo.ToToDoViewModel(), Operation.Create)); }
/// <summary> /// Creates a new todo-item. /// </summary> /// <param name="todo">The todo-item to create.</param> public async void Post(ToDoItemViewModel todo) { todo.UserId = userService.GetOrCreateUser(); TaskEntity toAdd = MapperDomainConfiguration.MapperInstance.Map <ToDoItemViewModel, TaskEntity>(todo); taskService.Create(toAdd); var added = await queueTask.Enqueue(todoService.CreateItem, todo); }
public IActionResult OnGet(int id) { Item = TaskService.AllTasks.FirstOrDefault(x => x.Id == id); if (Item == null) { return(RedirectToPage("RecentToDos")); } return(Page()); }
public static ToDoItemData ToItemData(this ToDoItemViewModel model) { return(new ToDoItemData { Name = model.Name, IsCompleted = model.IsCompleted, UserId = model.UserId, ToDoId = model.ToDoId }); }
public IActionResult Add(ToDoItemViewModel model) { var userEmail = HttpContext.User.FindFirst(ClaimTypes.Email).Value; var user = _userService.GetUserWithItems(userEmail); _itemService.AddTodoItem(model, user.Id); return(RedirectToAction("UserItems", "User")); }
//proprietatile obiectului sunt actualizate si se rescrie lista in fisierul text public void UpdateToDoItem(int id, ToDoItemViewModel item) { var itemEditat = currentToDos.First(x => x.ID == id); itemEditat.Title = item.Title; itemEditat.Description = item.Description; itemEditat.Done = item.Done; itemEditat.Date = item.Date; WriteItemsAsJson(); }
public static ToDo ToToDoDal(this ToDoItemViewModel viewModel) { return(new ToDo { Id = viewModel.ToDoId, Completed = viewModel.IsCompleted, Task = viewModel.Name, UserId = viewModel.UserId }); }
public MainWindow() { InitializeComponent(); DataContext = new ToDoItemViewModel { Title = "I must learn to type", Priority = 1 }; }
// to reduce risk of overposting. private ToDoItemDbModel ConvertViewModelToModel(ToDoItemViewModel item) { ToDoItemDbModel model = new ToDoItemDbModel() { Id = item.Id, Name = item.Name, IsDone = item.IsDone }; return(model); }
public void AddItemExist(ToDoItemViewModel toDo) { if (ReferenceEquals(toDo, null)) { throw new ArgumentNullException(); } AllToDoItems.Add(new ToDoToServer { item = toDo, MessageType = MessageType.None }); JSONWorker.Add(AllToDoItems); }
public ToDoDto Convert(ToDoItemViewModel source) { ToDoDto toDo = new ToDoDto { Id = source.Id, Description = source.Description, IsCompleted = source.IsCompleted }; return(toDo); }
public ToDoItemViewModel Convert(ToDoDto source) { ToDoItemViewModel viewModel = new ToDoItemViewModel { Id = source.Id, Description = source.Description, IsCompleted = source.IsCompleted }; return(viewModel); }
[HttpGet("{id}")] // GET api/task/5 public ActionResult <ToDoItemViewModel> Get(int id) { ToDoItemViewModel item = _data.GetTaskById(id); if (item == null) { return(NotFound()); } return(item); }
private ToDoItemViewModel getModelFromUserControl(GridCommandEventArgs e) { var userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); var toDoItemViewModel = new ToDoItemViewModel { Description = (userControl.FindControl("DescriptionTextBox") as TextBox).Text, WasDone = (userControl.FindControl("WasDoneCheckBox") as RadCheckBox).Checked ?? false, DueDate = (userControl.FindControl("DueDateTimePicker") as RadDateTimePicker).SelectedDate }; return(toDoItemViewModel); }