public Results.GenericResult <ToDoDto> Post([FromBody] ToDoDto model) { var result = new Results.GenericResult <ToDoDto>(); var validatorResult = validator.Validate(model); if (validatorResult.IsValid) { try { result.Result = appService.Create(model); result.Success = true; } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } } else { result.Errors = validatorResult.GetErrors(); } return(result); }
private async static Task Main() { Init(); var toDo = new ToDoDto { Description = "Eleventh ToDo" }; Console.WriteLine(CreateToDoRecord(toDo)); var filter = new FilterDto { //DescriptionFilter = "First", //IsCompletedFilter = true }; var paging = new PagingDto { PageSize = 5, PageNumber = 1 }; DisplayToDos(await GetAll(filter, paging)); //toDoService.DeleteToDoItem(3); //DisplayToDo(toDoService.GetToDoItemById(3)); //var toDo = toDoService.GetToDoItemById(1); //toDo.IsCompleted = true; //toDoService.UpdateToDoItem(toDo); DisplayToDo(await toDoService.GetToDoItemByIdAsync(3)); //DisplayToDos(GetAll()); }
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!"); } }
public void Put(int id, [FromBody] ToDoDto todo) { ToDoEntity foundEntity = _toDoRepository.GetById(id); todo.CopyTo(foundEntity); _unitOfWork.Commit(); }
public void AddToDo(ToDoDto toDoRequest, int userId) { var user = _userRepository.GetAll().FirstOrDefault(u => u.Id == userId); if (user == null) { throw new CustomException(null, null, "User not found!"); } ; if (toDoRequest == null) { throw new CustomException(null); } if (string.IsNullOrWhiteSpace(toDoRequest.Name)) { throw new CustomException(toDoRequest.Id, toDoRequest.Name, "Name is requried!"); } var subtasks = _mapper.Map <IEnumerable <SubTask> >(toDoRequest.SubTasks); var todo = new ToDo { Name = toDoRequest.Name, IsDone = toDoRequest.IsDone, UserId = userId, User = user, SubTasks = subtasks }; user.ToDoTasks.ToList().Add(todo); _toDoRepository.Insert(todo); }
public Response GetById(int id) { ToDoDto dto = new ToDoDto(); XDocument xmldoc; xmldoc = XDocument.Load("xml/file01.xml"); //add xml document XElement emp = xmldoc.Descendants("ToDo").FirstOrDefault(p => p.Element("id").Value == id.ToString()); if (emp != null) { dto.Id = Convert.ToInt32(emp.Element("id").Value); dto.Title = Convert.ToString(emp.Element("title").Value); dto.Description = Convert.ToString(emp.Element("description").Value); dto.DateAt = Convert.ToDateTime(emp.Element("dateAt").Value); dto.ExpireAt = Convert.ToDateTime(emp.Element("expireAt").Value); dto.Complete = Convert.ToInt32(emp.Element("complete").Value); dto.CompleteAt = Convert.ToDateTime(emp.Element("completeAt").Value); } Response response = new Response(); response.ResponseCode = "000"; response.ResponseMessage = "Success"; response.Data = dto; return(response); }
public ToDoDto GetTask(int userId, int taskId) { ToDo task = _toDoRepository.GetAll().FirstOrDefault(t => t.Id == taskId && t.UserId == userId); if (task == null) { throw new ToDoException($"Task with Id:{taskId} deos not exist"); } ToDoDto toDoDto = new ToDoDto() { Id = task.Id, TaskName = task.TaskName, TaskDescription = task.TaskDescription, IsCompleted = task.IsCompleted, UserId = task.UserId, SubTasks = _subTaskRepository.GetAll() .Where(s => s.ToDoId == task.Id) .Select(s => new SubTaskDto() { Id = s.Id, SubTaskName = s.SubTaskName, IsCompleted = s.IsCompleted, ToDoId = s.ToDoId }) }; return(toDoDto); }
public static ToDo MapToDo(ToDoDto toDoDto) { ToDo toDo = new ToDo() { Id = toDoDto.Id, TaskName = toDoDto.TaskName, TaskDescription = toDoDto.TaskDescription, IsCompleted = (bool)toDoDto.IsCompleted, UserId = toDoDto.UserId }; List <SubTask> listOfSubTask = new List <SubTask>(); foreach (SubTaskDto subTaskDto in toDoDto.SubTasks) { SubTask subTask = new SubTask() { Id = subTaskDto.Id, SubTaskName = subTaskDto.SubTaskName, IsCompleted = (bool)subTaskDto.IsCompleted, ToDoId = subTaskDto.ToDoId }; listOfSubTask.Add(subTask); } toDo.SubTasks = listOfSubTask; return(toDo); }
public int Add(ToDoDto toDoDto) { int id = GetId(); Database.Add(new ToDo(GetId(), toDoDto.Name, toDoDto.Done)); return(id); }
public Results.GenericResult Put(int id, [FromBody] ToDoDto model) { var result = new Results.GenericResult(); var validatorResult = validator.Validate(model); if (validatorResult.IsValid) { try { result.Success = appService.Update(model); if (!result.Success) { throw new Exception($"Todo {id} can't be updated"); } } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } } else { result.Errors = validatorResult.GetErrors(); } return(result); }
public void AddToDo(ToDoDto request) { var user = _userRepository.GetAll() .FirstOrDefault(x => x.Id == request.UserId); if (user == null) { throw new ToDoException("User does not exist"); } if (string.IsNullOrWhiteSpace(request.Text)) { throw new ToDoException("Text is a required field"); } if (string.IsNullOrWhiteSpace(request.Color)) { throw new ToDoException("Color is a required field"); } var todo = new ToDo { Text = request.Text, Color = request.Color, UserId = request.UserId }; _todoRepository.Insert(todo); }
public IActionResult PostAdd([FromBody] ToDoDto item) { item.Id = Guid.NewGuid(); _todos.InsertOne(Map(item)); return(Ok(item)); }
public async Task UpdateAsync(ToDoDto toDoDto) { var toDoDbModel = dbContext.ToDos.FirstOrDefault(t => t.Id == toDoDto.Id); toDoDbModel.Description = toDoDto.Description; toDoDbModel.IsCompleted = toDoDto.IsCompleted; await dbContext.SaveChangesAsync(); }
public async Task <ToDoDto> CreateAsync(ToDoDto dto) { var domain = dto.ToDomainModel(); var result = await toDoRepository.CreateAsync(domain); return(new ToDoDto(result)); }
public async Task <IActionResult> CriarTodo([FromBody] ToDoDto entity) { var todo = await _toDoRepository.Create(entity); return(Ok(new MessageDto { Mensagem = $"A Tarefa {todo.Id} foi criada com sucesso!" })); }
public async Task <Todo> Create(ToDoDto dto) { var todo = new Todo(dto); _appToDoContext.ToDos.Add(todo); await _appToDoContext.SaveChangesAsync(); return(todo); }
public async Task <IActionResult> Edit([FromServices] IUpdateService updateService, [FromRoute] Guid id, ToDoDto toDoDto) { toDoDto.Id = id; await updateService.UpdateAsync(toDoDto); return(Ok()); }
public ToDoDto Create(ToDoDto dto) { ToDo toDo = ConvertToEntity(dto); appContext.ToDo.Add(toDo); Save(); return(ConverToDto(toDo)); }
public async Task <int> CreateAsync(ToDoDto toDoDto) { ToDoDbModel toDo = toDoEntityConverter.Convert(toDoDto); await dbContext.AddAsync(toDo); await dbContext.SaveChangesAsync(); return(toDo.Id); }
private static void DisplayToDo(ToDoDto toDoDto) { if (toDoDto == null) { return; } string isCompleted = toDoDto.IsCompleted ? "Yes" : "No"; Console.WriteLine($"Id: {toDoDto.Id}\tDescription: {toDoDto.Description}\tIsCompleted: {isCompleted}"); }
public IActionResult Post([FromBody] ToDoDto toDo) { ToDo toAdd = _mapper.Map <ToDo>(toDo); _toDoService.Add(toAdd); toDo = _mapper.Map <ToDoDto>(toAdd); return(Ok(toDo.ToDoId)); }
public IActionResult Put(long id, [FromBody] ToDoDto value) { ToDo toUpdate = _mapper.Map <ToDo>(value); _toDoService.Update(id, toUpdate); value = _mapper.Map <ToDoDto>(toUpdate); return(Ok(value)); }
public int Create(ToDoDto dto) { var item = new ToDoItem() { Title = dto.Name, Priority = dto.Priority }; this._repository.Add(item); return(item.Id); }
public ToDoDbModel Convert(ToDoDto source) { return(source != null ? new ToDoDbModel { Id = source.Id, Description = source.Description, IsCompleted = source.IsCompleted } : null); }
private ToDo ConvertToEntity(ToDoDto dto) { return(new ToDo { Id = dto.Id, Subject = dto.Subject, Description = dto.Description, CreateDate = dto.CreateDate, //Tasks = }); }
public void Update(int id, ToDoDto toDoDto) { ToDo todo = Database.FirstOrDefault(x => x.Id == id); if (todo == null) { return; } todo.Name = toDoDto.Name; todo.Done = toDoDto.Done; }
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); }
public int Post([FromBody] ToDoDto todo) { ToDoEntity newEntity = new ToDoEntity(); todo.CopyTo(newEntity); _toDoRepository.Add(newEntity); _unitOfWork.Commit(); return(newEntity.Id); }
public void UpdateToDo(int id, ToDoDto toDo) { var result = _toDoRepository.GetToDo(id); Mapper.Map(toDo, result); if (!_toDoRepository.Save()) { throw new NotSavedException(500, "A problem happened while handling your request."); } }