public async Task <IActionResult> SaveTodoEntity([FromBody] TodoVM pTodo) { try { if (pTodo.Id.HasValue && pTodo.Id.Value > 0) { // The user application exists TodoEntity tde = _repository.GetTodoList().Where(ua => ua.Id == pTodo.Id).FirstOrDefault <TodoEntity>(); setTodoEntity(pTodo, tde); bool isSaved = await _repository.SaveChangesAsync(); // return OK return(Ok(new { Data = pTodo, Status = "Success" })); } else { //the user application doesn't exists TodoEntity tde = new TodoEntity(); setTodoEntity(pTodo, tde); tde = await _repository.InsertTodoEntity(tde); pTodo.Id = tde.Id; // return OK return(Ok(new { Data = pTodo, Status = "Success" })); } } catch (Exception ex) { _logger.LogError($"{ex.Message}"); return(BadRequest(new { Status = "Error", Error = $"{ex.Message}" })); } }
public async Task <IActionResult> PutTodoEntity(Guid id, TodoEntity todoEntity) { if (id != todoEntity.Id) { return(BadRequest()); } context.Entry(todoEntity).State = EntityState.Modified; try { await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoEntityExists(id)) { return(NotFound()); } throw; } return(NoContent()); }
public ActionResult <TodoItemResponseDTO> PutTodoItem(int id, TodoItemUpsertDTO todoItem) { try { if (todoItem == null) { return(BadRequest()); } var existingItem = _todoRepository.GetSingle(id); if (existingItem == null) { return(NotFound()); } TodoEntity item = _mapper.Map <TodoEntity>(todoItem); //todo look at me _todoRepository.Update(id, item); if (!_todoRepository.Save()) { throw new Exception("Updating a fooditem failed on save."); } TodoItemResponseDTO responseItem = _mapper.Map <TodoItemResponseDTO>(item); return(responseItem); } catch (Exception ex) { _logger.LogError(String.Concat("An unhanded error occured when updating items: ", ex.Message)); return(StatusCode(500)); } }
public async Task <ActionResult <TodoEntity> > PostTodoEntity(TodoEntity todoEntity) { context.TodoEntities.Add(todoEntity); await context.SaveChangesAsync(); return(CreatedAtAction("GetTodoEntity", new { id = todoEntity.Id }, todoEntity)); }
public ActionResult AddTodo([FromBody] TodoCreateDto todoCreateDto) { if (todoCreateDto == null) { return(BadRequest()); } TodoEntity item = _mapper.Map <TodoEntity>(todoCreateDto); item.Created = DateTime.UtcNow; TodoEntity newTodoEntity = _todoRepository.Add(item); if (!_todoRepository.Save()) { throw new Exception("Adding an item failed on save."); } var dto = _mapper.Map <TodoDto>(newTodoEntity); _todoHubContext.Clients.All.SendAsync("TodoAdded", dto); return(CreatedAtRoute( nameof(GetSingle), new { id = newTodoEntity.Id }, dto)); }
public ActionResult <TodoModel> CreateTodoItem(TodoModel item, string group) { if (item == null || string.IsNullOrEmpty(item.Content)) { _logger.LogInformation(LoggingEvents.InsertItem, "Empty item"); return(BadRequest()); } var entity = new TodoEntity { PartitionKey = group, RowKey = Guid.NewGuid().ToString(), Completed = item.Completed, Content = item.Content, Due = item.Due }; _repository.CreateTodoItem(entity); item.Id = entity.RowKey; item.Group = entity.PartitionKey; _logger.LogInformation(LoggingEvents.InsertItem, "Item {id} created in {group}", entity.RowKey, group); return(CreatedAtAction(nameof(GetTodoItem), new { group = entity.PartitionKey, id = entity.RowKey }, item)); }
// Create Todo Item List public void CreateOrUpdate(TodoEntity entity) { // perform insert and update operation in Db var operation = TableOperation.InsertOrReplace(entity); todoTable.Execute(operation); }
public void DeleteTodo(int id) { TodoEntity todoEntity = todoDbContext.TodoEntities.First(x => x.Id == id); todoDbContext.TodoEntities.Remove(todoEntity); todoDbContext.SaveChanges(); }
public async Task <TodoEntity> UpdateAsync(TodoEntity entity) { EntityEntry <TodoEntity> updated = _dbSet.Update(entity); await _dbContext.SaveChangesAsync(); return(updated.Entity); }
// Delete Item public void Delete(TodoEntity entity) { // perform insert and update operation in Db var operation = TableOperation.Delete(entity); todoTable.Execute(operation); }
/// <inheritdoc/> public async Task <TodoDto> CreateTodo(TodoDto dto) { TodoEntity newTodoEntity = _todoMapper.Map(dto); TodoEntity createdTodoEntity = await _todoRepository.AddAsync(newTodoEntity); return(_todoMapper.Map(createdTodoEntity)); }
public async Task <TodoDto> AddAsync(NewTodoDto model) { TodoEntity entity = _mapper.Map <TodoEntity>(model); TodoEntity user = await _repository.AddAsync(entity); return(_mapper.Map <TodoDto>(user)); }
public async Task <ActionResult <TodoDto> > UpdateTodo(Guid id, [FromBody] TodoUpdateDto updateDto) { if (updateDto == null) { return(BadRequest()); } TodoEntity singleById = _todoRepository.GetSingle(id); if (singleById == null) { return(NotFound()); } updateDto.Value = updateDto.Value ?? singleById.Value; _mapper.Map(updateDto, singleById); TodoEntity updatedTodo = _todoRepository.Update(id, singleById); if (!_todoRepository.Save()) { throw new Exception("Updating an item failed on save."); } var updatedDto = _mapper.Map <TodoDto>(updatedTodo); await _todoHubContext.Clients.All.SendAsync("todo-updated", updatedDto); return(Ok(updatedDto)); }
/// <summary> /// 获取代办列表 /// </summary> /// <param name="loginName"></param> /// <param name="user"></param> public static List <TodoEntity> GetTodoList(string loginName, UserInfo user) { List <TodoEntity> list = new List <TodoEntity>(); string auditorStr = ""; SecurityBll.LogIn(loginName, user); if (user != null && user.Roles != null && user.inn != null) { List <PrManageModel> prList = GetPrTodoList(user); List <ExpenseReimbursementModel> erList = GetErTodoList(user); List <TripReimbursementModel> trList = GetTrTodoList(user); if (prList != null && prList.Count > 0) { foreach (var item in prList) { TodoEntity entity = new TodoEntity(); entity.RecordName = "PR单" + "(" + item.b_PrRecordNo + ")"; entity.Applicant = item.b_Applicant; entity.FlowStatus = item.status; entity.ApplicationDate = item.nb_RaisedDate.ToString("yyyy-MM-dd"); entity.AuditorStr = ActivityDA.GetActivityOperator(user.inn, item.activityId); entity.LinkStr = "https://oa.bordrin.com/PrManage"; list.Add(entity); } } if (erList != null && erList.Count > 0) { foreach (var item in erList) { TodoEntity entity = new TodoEntity(); entity.RecordName = "费用报销单" + "(" + item.b_RecordNo + ")"; entity.Applicant = item.b_Employee; entity.FlowStatus = item.status; entity.ApplicationDate = item.nb_ApplicationDate.GetValueOrDefault().ToString("yyyy-MM-dd"); entity.AuditorStr = ActivityDA.GetActivityOperator(user.inn, item.activityId); entity.LinkStr = "https://oa.bordrin.com/ExpenseReimbursement"; list.Add(entity); } } if (trList != null && trList.Count > 0) { foreach (var item in trList) { TodoEntity entity = new TodoEntity(); entity.RecordName = "差旅报销单" + "(" + item.b_RecordNo + ")"; entity.Applicant = item.b_Employee; entity.FlowStatus = item.status; entity.ApplicationDate = item.nb_ApplicationDate.GetValueOrDefault().ToString("yyyy-MM-dd"); entity.AuditorStr = ActivityDA.GetActivityOperator(user.inn, item.activityId); entity.LinkStr = "https://oa.bordrin.com/TripReimbursement"; list.Add(entity); } } } return(list); }
public async Task <TodoEntity> AddAsync(TodoEntity entity) { EntityEntry <TodoEntity> added = await _dbSet.AddAsync(entity); await _dbContext.SaveChangesAsync(); return(added.Entity); }
public async Task <ActionResult <TodoApiModel> > Put(string id, [FromBody] TodoRequestApiModel value) { var todo = new TodoEntity(new TodoId(id), value.Task); return(Result( await repository.Update(todo) )); }
public async Task <ActionResult <TodoApiModel> > Post([FromBody] TodoRequestApiModel value) { var todo = new TodoEntity(TodoId.NewId(), value.Task); return(Result( await repository.Create(todo) )); }
public void Can_Validate_A_Valid_Todo(string task) { var subject = new TodoValidator(); var todo = new TodoEntity(new TodoId("123"), task); var result = subject.Validate(todo).Result; Assert.True(result.IsRight); }
// =============================================================================================== // Private methods // =============================================================================================== private void setTodoEntity(TodoVM tdv, TodoEntity tde) { //wua.Id = pUserApp.Id.Value; tde.Description = tdv.Description; tde.DueDate = tdv.DueDate; tde.Priority = tdv.Priority; tde.IsCompleted = tdv.IsCompleted; tde.TdUserId = tdv.TdUserId; }
/// <inheritdoc/> public async Task <TodoDto> UpdateTodo(Guid id, TodoDto dto) { TodoEntity existingTodoEntity = await _todoRepository.GetByIdAsync(id); TodoEntity updatableTodoEntity = _todoMapper.Map(dto, existingTodoEntity); await _todoRepository.UpdateAsync(updatableTodoEntity); return(_todoMapper.Map(updatableTodoEntity)); }
/// <inheritdoc/> public TodoEntity Map(TodoDto dto, TodoEntity entity) { ArgumentNullException.ThrowIfNull(dto, nameof(dto)); ArgumentNullException.ThrowIfNull(entity, nameof(entity)); entity.Description = dto.Description; entity.IsDone = dto.IsDone; return(entity); }
public void Can_Validate_An_Invalid_Todo(string task) { var subject = new TodoValidator(); var todo = new TodoEntity(new TodoId("123"), task); var result = subject.Validate(todo).Result; Assert.True(result.IsLeft); Assert.Equal(DomainErrorCode.FailedValidation, result.LeftAsEnumerable().Head.ErrorCode); }
public async Task <TodoDto> UpdateAsync(long id, UpdateTodoDto model) { TodoEntity entity = await _repository.GetByIdAsync(id); _mapper.Map(model, entity); TodoEntity user = await _repository.UpdateAsync(entity); return(_mapper.Map <TodoDto>(user)); }
public IActionResult Delete(int id) { TodoEntity u = r.Delete(id); if (u != null) { return(Ok(u)); } return(NotFound()); }
public IActionResult Put(int id, [FromBody] TodoEntity item) { TodoEntity u = r.Update(id, item); if (u != null) { return(Ok(u)); } return(NotFound()); }
public ActionResult Edit(TodoEntity model) { var item = repository.Get(model.Group, model.Id); item.Completed = model.Completed; item.Content = model.Content; item.Due = model.Due; repository.Upsert(item); return(RedirectToAction("Index")); }
public ActionResult Create(TodoEntity model) { repository.Create(new Models.DAO.TodoEntity { PartitionKey = model.Group, RowKey = Guid.NewGuid().ToString(), Content = model.Content, Due = model.Due }); return(RedirectToAction("Index")); }
public TodoEntity Map(TodoDto dto, TodoEntity entity) { if (dto == null || entity == null) { return(null); } entity.Description = dto.Description; entity.IsDone = dto.IsDone; return(entity); }
public ActionResult <TodoDto> GetSingle(Guid id) { TodoEntity entity = _todoRepository.GetSingle(id); if (entity == null) { return(NotFound()); } return(Ok(_mapper.Map <TodoDto>(entity))); }
/// <inheritdoc/> public TodoDto Map(TodoEntity entity) { ArgumentNullException.ThrowIfNull(entity, nameof(entity)); return(new TodoDto { Id = entity.Id, Description = entity.Description, IsDone = entity.IsDone, }); }