Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
MyTaskManger/AddTaskPage.xaml.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
78 lines (63 sloc)
2.19 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using MyDailyTaskManger.Models; | |
using Xamarin.Forms; | |
using Newtonsoft.Json; | |
using System.IO; | |
namespace MyDailyTaskManger | |
{ | |
public partial class AddTaskPage : ContentPage | |
{ | |
private String FileName; | |
public AddTaskPage() | |
{ | |
InitializeComponent(); | |
FileName = null; | |
} | |
public async void HandleForm(object sender, EventArgs eventArgs) | |
{ | |
var task = new Task(); | |
task.title = this.title.Text; | |
task.detail = this.details.Text; | |
task.dateCreated = DateTime.Now.ToString(); | |
if (null != this.FileName) | |
{ | |
string FullFileName = Path.Combine(App.FolderPath, this.FileName); | |
task.fileName = FullFileName; | |
string json = JsonConvert.SerializeObject(task); | |
File.WriteAllText(FullFileName, json); | |
bool ok = await DisplayAlert( | |
"Success", | |
$"{this.FileName} File updated", | |
"Done", | |
"Contine update" | |
); | |
if (ok == true) | |
{ | |
ViewTaskPage page = new ViewTaskPage(task); | |
// page.BindingContext = task; | |
await Navigation.PushAsync(page); | |
} | |
} else | |
{ | |
this.FileName = $"{Path.GetRandomFileName()}.task.txt"; | |
string FullFileName = Path.Combine(App.FolderPath, this.FileName); | |
task.fileName = FullFileName; | |
string json = JsonConvert.SerializeObject(task); | |
File.WriteAllText(FullFileName, json); | |
bool ok = await DisplayAlert( | |
"Success", | |
$"{this.FileName} File Created", | |
"Done", | |
"Contine update" | |
); | |
if (ok == true) | |
{ | |
ViewTaskPage page = new ViewTaskPage(task); | |
// page.BindingContext = task; | |
await Navigation.PushAsync(page); | |
} | |
} | |
} | |
} | |
} |