public TodoItemPage(TodoItem todoItem, TodoListViewModel lvm) { InitializeComponent(); this.TodoItemViewModel = new TodoItemViewModel { Navigation = this.Navigation, TodoListViewModel = lvm }; // addition if (todoItem == null) { this.TodoItemViewModel.IsAdding = true; } // editing else { this.TodoItemViewModel.TodoItem = todoItem.ShallowCopy(); this.TodoItemViewModel.Id = todoItem.Id; this.TodoItemViewModel.Name = todoItem.Name; this.TodoItemViewModel.Description = todoItem.Description; this.TodoItemViewModel.Date = todoItem.Date; this.TodoItemViewModel.Time = todoItem.Time; } this.BindingContext = this.TodoItemViewModel; }
public IHttpActionResult PutTodoList(int id, TodoListViewModel todoListDto) { if (!ModelState.IsValid) { return(Message(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState))); } if (id != todoListDto.TodoListId) { return(StatusCode(HttpStatusCode.BadRequest)); } TodoList todoList = todoListDto.ToEntity(); if (!String.Equals(db.Entry(todoList).Entity.UserId, User.Identity.GetUserId(), StringComparison.OrdinalIgnoreCase)) { // Trying to modify a record that does not belong to the user return(StatusCode(HttpStatusCode.Unauthorized)); } db.Entry(todoList).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(StatusCode(HttpStatusCode.InternalServerError)); } return(StatusCode(HttpStatusCode.OK)); }
public IActionResult List(string p) { const int PAGE_SIZE = 10; int? uid = HttpContext.Session.GetInt32("uid"); if (uid == null) { return(RedirectToAction("Login", "Login")); } int page; if (!Int32.TryParse(p, out page)) { page = 1; } int count = TodoTaskService.FindCountByUser((int)uid); int pages = count % PAGE_SIZE == 0 ? count / PAGE_SIZE : count / PAGE_SIZE + 1; if (page > pages) { page = pages; } if (page <= 0) { page = 1; } List <TodoTask> todos = TodoTaskService.FindTodoTaskByUserAndPageAndPagesize((int)uid, page, PAGE_SIZE); TodoListViewModel todoListViewModel = new TodoListViewModel(todos, pages, page); return(View(todoListViewModel)); }
protected override async void OnAppearing() { base.OnAppearing(); ViewModel = new TodoListViewModel(App.DataRepository); await ViewModel.LoadData(); }
public IActionResult Edit(int id) { TodoListViewModel viewModel = new TodoListViewModel(); viewModel.EditableItem = viewModel.TodoItems.FirstOrDefault(x => x.Id == id); return(View("Index", viewModel)); }
public IActionResult CreateUpdate(TodoListViewModel viewModel) { if (ModelState.IsValid) { using (var db = DbHelper.GetConnection()) { if (viewModel.EditableItem.Id <= 0) { viewModel.EditableItem.AddDate = DateTime.Now; db.Insert <TodoListItem>(viewModel.EditableItem); } else { TodoListItem dbItem = db.Get <TodoListItem>(viewModel.EditableItem.Id); var result = TryUpdateModelAsync <TodoListItem>(dbItem, "EditableItem"); db.Update <TodoListItem>(dbItem); } } return(RedirectToAction("Index")); } else { return(View("Index", new TodoListViewModel())); } }
public IHttpActionResult DeleteTodoList(int id) { TodoList todoList = db.TodoLists.Find(id); if (todoList == null) { return(StatusCode(HttpStatusCode.NotFound)); } if (!String.Equals(db.Entry(todoList).Entity.UserId, User.Identity.GetUserId(), StringComparison.OrdinalIgnoreCase)) { // Trying to delete a record that does not belong to the user return(StatusCode(HttpStatusCode.Unauthorized)); } TodoListViewModel todoListDto = new TodoListViewModel(todoList); db.TodoLists.Remove(todoList); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(StatusCode(HttpStatusCode.InternalServerError)); } return(Content(HttpStatusCode.OK, todoListDto)); }
public async Task UpdateAsync(int id, TodoListViewModel todoList) { var list = await this.GetListById(id); list.Title = todoList.Title; await this.Update(list); }
public async Task <ActionResult> Message(TodoListViewModel item) { await userTask.MessageSend(item); TempData["Success"] = "The message has been added!"; return(RedirectToAction("Index")); }
public IActionResult List(string key) { var model = new TodoListViewModel() { Todos = _todoHelper.GetTodosByTitle(key) }; return(View(model)); }
public IActionResult Index(int id = 0) { var model = new TodoListViewModel { Todos = id == 0 ? _todoService.GetAll() : _todoService.GetCompleted() }; return(View(model)); }
public ViewResult List() { var todoViewModel = new TodoListViewModel(); todoViewModel.Todos = _todoRepository.AllTodos; todoViewModel.CurrentUser = "******"; return(View(todoViewModel)); }
public MainWindow() { this.InitializeComponent(); ResizeWindow(this, 480, 800); _service = new RemoteTodoService(); _viewModel = new TodoListViewModel(this, _service); mainContainer.DataContext = _viewModel; }
public async Task MessageSend(TodoListViewModel item) { var TaskToUpdate = context.Set <TodoListData>().FirstOrDefault(x => x.Id == item.Id); TaskToUpdate.Message = item.Message; context.TodoListData.Update(TaskToUpdate); await context.SaveChangesAsync(); }
public void SaveList(TodoListViewModel model) { using (var db = _provider.GetDatabase()) { var collection = db.GetCollection <TodoListViewModel>(); if (!collection.Update(model)) { collection.Insert(model); } } }
public TodoListPage() { InitializeComponent(); TodoListViewModel = new TodoListViewModel() { Navigation = this.Navigation }; this.BindingContext = TodoListViewModel; }
public MainWindow() { InitializeComponent(); _controller = new CrossController(); _todoListViewModel = new TodoListViewModel(_controller); _todoListViewModel.OnError += TodoListViewModel_OnError; _todoListViewModel.BlockingOperationsStarted += OnBlockingOperationsStarted; _todoListViewModel.BlockingOperationsFinished += OnBlockingOperationsFinished; Todo_ListView.ItemsSource = _todoListViewModel.TodoList; }
public MainPage() { InitializeComponent(); ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(450, 800)); ApplicationView.PreferredLaunchViewSize = new Size(450, 800); ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; _viewModel = new TodoListViewModel(this, (Application.Current as App)?.TodoService); DataContext = _viewModel; }
public TodoList(TodoListViewModel viewModel) { this.BindingContext = viewModel; InitializeComponent(); // OnPlatform<T> doesn't currently support the "Windows" target platform, so we have this check here. if (Device.OS == TargetPlatform.Windows || Device.OS == TargetPlatform.WinPhone) { syncButton.IsVisible = true; } }
/// <inheritdoc /> public async Task <TodoListViewModel> GetListAsync(CancellationToken cancellationToken) { IList <TodoItem> items = await _repository.GetItemsAsync(cancellationToken); var result = new TodoListViewModel(); foreach (var todo in items) { result.Items.Add(MapItem(todo)); } return(result); }
public HttpResponseMessage CreateList([FromBody] TodoListViewModel list) { try { var newList = EntityConvert <TodoListViewModel, TodoListModel>(list); _listService.Add(newList); return(Request.CreateResponse(HttpStatusCode.Created, newList)); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public async Task <ActionResult> Edit(TodoListViewModel item) { if (ModelState.IsValid) { await adminTask.EditTaskForUser(item); TempData["Success"] = "The item has been updated!"; return(RedirectToAction("Index")); } return(View(item)); }
public HttpResponseMessage UpdateList(int id, TodoListViewModel newList) { try { var list = _listService.GetById(id); list.Name = newList.Name; _listService.Update(list); return(Request.CreateResponse(HttpStatusCode.OK, newList)); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public void EditTodoList(int id, [FromBody] TodoListViewModel todoList) { var item = _todoListService.GetTodoListById(id); if (item == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Не удалось найти указанный элемент")); } if (User.Identity.GetUserId() != item.ApplicationUserEntityId) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Доступ к ресурсу запрещен")); } _todoListService.UpdateTodoList(_mapper.Map <TodoListViewModel, TodoListDTO>(todoList)); }
public TimePickerPage(TodoItemViewModel todoItemViewModel, TodoListViewModel todoListViewModel) { InitializeComponent(); TimePickerViewModel = new TimePickerViewModel() { TodoItemViewModel = todoItemViewModel, TodoListViewModel = todoListViewModel, Navigation = this.Navigation, Time = todoItemViewModel.Time }; this.BindingContext = TimePickerViewModel; }
public async Task EditTaskForUser(TodoListViewModel item) { var TaskToUpdate = this.context.Set <TodoListData>().FirstOrDefault(x => x.Id == item.Id); TaskToUpdate.Content = item.Content; TaskToUpdate.Datetime = item.Datetime; TaskToUpdate.ApplicationUsersId = item.ApplicationUsersId; TaskToUpdate.Priority = item.Priority; TaskToUpdate.LeadTime = item.LeadTime; context.TodoListData.Update(TaskToUpdate); await context.SaveChangesAsync(); }
public async Task <ActionResult> Edit(TodoListViewModel item) { if (ModelState.IsValid) { var currentUser = userTask.UserAuthorizationCheck(User.Identity.Name); await userTask.EditTaskForUser(item, currentUser.Id); TempData["Success"] = "The item has been updated!"; return(RedirectToAction("Index")); } return(View(item)); }
public async Task CreateTaskForUser(TodoListViewModel item) { TodoListData items = new TodoListData { Content = item.Content, Datetime = item.Datetime, ApplicationUsersId = item.ApplicationUsersId, Priority = item.Priority, LeadTime = item.LeadTime }; context.TodoListData.Add(items); await context.SaveChangesAsync(); }
public async Task <TodoListViewModel> GetTaskIdForEdit(int id) { var item = await context.TodoListData.FindAsync(id); TodoListViewModel modelToReturn = new TodoListViewModel { Content = item.Content, Datetime = item.Datetime, Id = item.Id, Priority = item.Priority, LeadTime = item.LeadTime }; return(modelToReturn); }
public async Task <ActionResult> Index() { var serviceResponse = await TodoService.ListAsync(new ListTodosServiceRequest { Username = Username }); var items = serviceResponse.EnsureSuccessfull(); var model = new TodoListViewModel { Items = Mapper.Map <IEnumerable <TodoListItemViewModel> >(items) }; return(View(model)); }
public ShellViewModel(TodoListViewModel todoList, FilterViewModel filter) { this.TodoList = todoList; this.Filter = filter; }