public ActionResult Create(ToDoBindingModel model)
        {
            var ctx    = ApplicationDbContext.Create();
            var userId = User.Identity.GetUserId();

            var todoModel = AutoMapping.Mapper.Map <ToDoBindingModel, ToDoModel>(model);

            todoModel.UserId = userId;

            var lastRecord = ctx.ToDoList.Where(r => r.UserId == userId).OrderByDescending(r => r.RecordNumber).FirstOrDefault();

            if (lastRecord != null)
            {
                todoModel.RecordNumber = lastRecord.RecordNumber + 1;
            }
            else
            {
                todoModel.RecordNumber++;
            }

            ctx.ToDoList.Add(todoModel);
            ctx.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Example #2
0
        private async void ToDoes_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            // *************** TAKE THESE CODES TO THE SERVICE LAYER *********************

            ToDoBindingModel toDoBindingModel = (ToDoBindingModel)sender;

            var result = await _toDoService.GetByIdAsync(toDoBindingModel.Id);

            if (result.HasError || result.Data == null)
            {
                System.Windows.Forms.MessageBox.Show("Could not find the record in database");
                return;
            }

            ToDoDto toDoDto = result.Data;

            toDoDto.IsCompleted = toDoBindingModel.IsCompleted;
            toDoDto.IsDeleted   = toDoBindingModel.IsDeleted;
            toDoDto.Text        = toDoBindingModel.Text;

            result = await _toDoService.UpdateAsync(toDoDto);

            if (result.HasError)
            {
                System.Windows.Forms.MessageBox.Show("An error has occured while updating the record!");
            }
        }
Example #3
0
        public ToDoViewModel UpdateToDo(ToDoBindingModel toDoUpdateModel, Guid toDoId, Guid userId)
        {
            var toDoUpdate = _mapper.Map <ToDo>(toDoUpdateModel);
            var toDo       = _toDoRepository.UpdateToDo(toDoUpdate, toDoId, userId);

            return(_mapper.Map <ToDoViewModel>(toDo));
        }
Example #4
0
        public ICollection <ToDoViewModel> AddToDo(ToDoBindingModel toDoModel, Guid userId)
        {
            var toDo  = _mapper.Map <ToDo>(toDoModel);
            var toDos = _toDoRepository.AddToDo(toDo, userId);

            return(_mapper.Map <ICollection <ToDoViewModel> >(toDos));
        }
Example #5
0
        public IActionResult UpdateToDo([FromBody] ToDoBindingModel toDoModel, [FromRoute] Guid id)
        {
            var userId           = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));
            var updatedToDoModel = _toDoService.UpdateToDo(toDoModel, id, userId);

            return(Ok(updatedToDoModel));
        }
Example #6
0
        public IActionResult AddToDo(ToDoBindingModel toDoModel)
        {
            var userId     = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));
            var toDosModel = _toDoService.AddToDo(toDoModel, userId);

            return(Ok(toDosModel));
        }
Example #7
0
        public async Task <IActionResult> OnGet(int id)
        {
            var toDoDto = await toDoService.GetToDoItemByIdAsync(id);

            var toDoItem = new ToDoBindingModel
            {
                Id          = toDoDto.Id,
                Description = toDoDto.Description,
                IsCompleted = toDoDto.IsCompleted
            };

            ToDoItemEditModel = toDoItem;
            return(Page());
        }
        public ActionResult Done(ToDoBindingModel model)
        {
            var ctx    = ApplicationDbContext.Create();
            var userId = User.Identity.GetUserId();

            var oldTodo = ctx.ToDoList.FirstOrDefault(t => t.Id == model.Id && t.UserId == userId);

            if (oldTodo != null)
            {
                oldTodo.Status = model.Status;
            }

            ctx.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
        public IActionResult ListCategory(ToDoBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //TODO: Validate the parameters
            var service = new ToDoService();
            var tasks   = service.GetToDoItems(model.Category, model.Username)
                          .Select(x => new ToDoItemViewModel.Task(x.Number, x.Title));
            var viewModel = new ToDoItemViewModel(tasks, model.Category, model.Username);

            return(View(viewModel));
        }
        public ActionResult Edit(ToDoBindingModel model)
        {
            var ctx    = ApplicationDbContext.Create();
            var userId = User.Identity.GetUserId();

            var newTodoModel = AutoMapping.Mapper.Map <ToDoBindingModel, ToDoModel>(model);

            newTodoModel.UserId = userId;

            var oldTodo = ctx.ToDoList.FirstOrDefault(t => t.Id == newTodoModel.Id && t.UserId == userId);

            if (oldTodo != null)
            {
                oldTodo.DueDate = newTodoModel.DueDate;
                oldTodo.Title   = newTodoModel.Title;
            }

            ctx.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }