public async Task <T> DeleteToDoObject <T>(ToDoEntity toDoEntity)
            where T : class
        {
            var connectionString = _configuration.GetConnectionString("MongoConnection");
            var table            = "todoobject";
            //var table = toDoEntity.TableName;
            var userId        = toDoEntity.UserId;
            var title         = toDoEntity.Title;
            var deletedObject = new DeleteToDoObjectResponse();

            try
            {
                await _dBInterface.Delete <ToDoEntity>(connectionString, table, userId, title);

                _logger.LogInformation("Successfully deleted ToDoObject");
                deletedObject.Title = title;
                return(deletedObject as T);
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to delete the ToDoObject", ex);
            }

            return(null);
        }
        public ToDoEntity AddToDoList(ToDoEntity toDoEntity)
        {
            toDoEntity.CreatedDate = DateTime.Now;
            toDoListRepository.AddToDoList(toDoEntity);

            return(toDoEntity);
        }
Example #3
0
        public async Task WithValidObject_GetAllToDoObjects_ReturnsListOfObjects()
        {
            var fakeDb     = A.Fake <IDBInterface>();
            var fakeConfig = A.Fake <IConfiguration>();
            var fakeLogger = A.Fake <ILogger <GetToDoObjectService> >();

            var sut = new GetToDoObjectService(fakeDb, fakeConfig, fakeLogger);

            var toDoEntity1 = new ToDoEntity()
            {
                Description = "My First To Do Object"
            };
            //var toDoEntity2 = new ToDoEntity("userId", "title") { Description = "My Second To Do Object" };

            //A.CallTo(() => fakeDb.ReadAll<ToDoEntity>(A<string>._, A<string>._)).Returns<ToDoEntity>(
            //  new List<ToDoEntity>
            //  {
            //    toDoEntity1,
            //    toDoEntity2
            //  });

            //var toDoObjects = await sut.GetAllToDoObjects();
            //var count = toDoObjects.Count;

            //var toDoDesc1 = toDoObjects[0].Description;
            //var toDoDesc2 = toDoObjects[1].Description;

            //Assert.That(toDoObjects, Is.Not.Null);
            //Assert.That(count, Is.EqualTo(2));
            //Assert.That(toDoDesc1, Is.EqualTo("My First To Do Object"));
            //Assert.That(toDoDesc2, Is.EqualTo("My Second To Do Object"));
        }
Example #4
0
        public async Task <IActionResult> PutToDoEntity(int 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());
                }
                else
                {
                    throw;
                }
            }

            return(Content("Updated"));
        }
        public void Update(int id, ToDoDto toDoDto)
        {
            ToDoEntity foundEntity = _context.Set <ToDoEntity>().SingleOrDefault(item => item.Id == id);

            toDoDto.CopyTo(foundEntity);
            _unitOfWork.Commit();
        }
        public async Task <ToDoEntity> UpdateToDoObject(UpdateToDoObjectRequest request)
        {
            var updatedEntity    = new ToDoEntity();
            var connectionString = _configuration.GetConnectionString("MongoConnection");
            var table            = TableNames.todoobject.ToString();
            var userId           = request.UserId;
            var title            = request.Title;
            var description      = request.Description;
            var priority         = request.Priority;
            var newTitle         = request.NewTitle;

            try
            {
                await _dBInterface.Update <ToDoEntity>(userId, title, description, priority, newTitle);

                // Get the newly updated ToDoObject
                if (!string.IsNullOrEmpty(newTitle))
                {
                    updatedEntity = await _dBInterface.Read(userId, newTitle);
                }
                else
                {
                    updatedEntity = await _dBInterface.Read(userId, title);
                }

                _logger.LogInformation("Successfully updated ToDoObject");
            }
            catch (Exception ex)
            {
                _logger.LogError("Could not find the given ToDoObject", ex);
            }

            return(updatedEntity);
        }
Example #7
0
        public async Task <ActionResult <ToDoEntity> > PostToDoEntity(ToDoEntity toDoEntity)
        {
            _context.ToDos.Add(toDoEntity);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetToDoEntity", new { id = toDoEntity.Id }, toDoEntity));
        }
Example #8
0
 public ToDoDto(ToDoEntity toDoEntity)
 {
     Id           = toDoEntity.Id;
     Name         = toDoEntity.Name;
     Done         = toDoEntity.Done;
     CreationDate = toDoEntity.CreationDate;
 }
Example #9
0
        public void Put(int id, [FromBody] ToDoDto todo)
        {
            ToDoEntity foundEntity = _toDoRepository.GetById(id);

            todo.CopyTo(foundEntity);
            _unitOfWork.Commit();
        }
Example #10
0
 public ToDo(
     ToDoEntity toDoEntity)
 {
     this.Id          = toDoEntity.Id;
     this.Status      = toDoEntity.Status;
     this.Description = toDoEntity.Description;
 }
Example #11
0
        public async Task <ToDoEntity> AddOne(ToDoEntity ToDo)
        {
            var res = await _dbSet.AddAsync(ToDo);

            await _context.SaveChangesAsync();

            return(res.Entity);
        }
        public async Task Update(ToDoEntity updatedTodo)
        {
            await Task.Run(() => {
                var todo = ToDoDbContext.ToDosSet.RemoveAll(x => x.Id == updatedTodo.Id);

                ToDoDbContext.ToDosSet.Add(updatedTodo);
            });
        }
Example #13
0
        public async Task <ToDoEntity> UpdateOne(ToDoEntity ToDo)
        {
            var res = _dbSet.Update(ToDo);

            await _context.SaveChangesAsync();

            return(ToDo);
        }
        public int Create(ToDoDto toDoDto)
        {
            ToDoEntity newEntity = new ToDoEntity();

            toDoDto.CopyTo(newEntity);
            _context.Set <ToDoEntity>().Add(newEntity);
            _unitOfWork.Commit();
            return(newEntity.Id);
        }
Example #15
0
        public void Save()
        {
            var entity = new ToDoEntity(
                Guid.NewGuid().ToString(),
                Title,
                ImportantLevel,
                UrgentLevel);

            _toDoRepository.Save(entity);
        }
        public ToDoEntity UpdateToDoList(ToDoEntity toDoEntity)
        {
            ToDoEntity toDoEntityId = toDoListRepository.GetToDo(toDoEntity.Id);

            toDoEntity.UpdatedDate   = DateTime.Now;
            toDoEntityId.UpdatedDate = toDoEntity.UpdatedDate;
            toDoEntityId.Description = toDoEntity.Description;
            toDoListRepository.UpdateToDoList(toDoEntityId);
            return(toDoEntity);
        }
Example #17
0
        public int Post([FromBody] ToDoDto todo)
        {
            ToDoEntity newEntity = new ToDoEntity();

            todo.CopyTo(newEntity);

            _toDoRepository.Add(newEntity);

            _unitOfWork.Commit();
            return(newEntity.Id);
        }
Example #18
0
        public async Task <ToDoItem> InsertNewToDoItem(string userId, ToDoItem toDo)
        {
            ToDoEntity entity = _mapper.Map <ToDoEntity>(toDo);

            entity.IdentityId = userId;
            entity.TimeStamp  = DateTime.Now;
            _db.ToDos.Add(entity);
            int numberOfChanges = await _db.SaveChangesAsync();

            return(_mapper.Map <ToDoItem>(entity));
        }
Example #19
0
        private async Task DeleteAsync(
            ToDoEntity toDoEntity,
            CloudTable cloudTable)
        {
            var tableOperation =
                TableOperation.Delete(toDoEntity);

            var tableResult =
                await cloudTable.ExecuteAsync(tableOperation);

            tableResult.EnsureSuccessStatusCode();
        }
Example #20
0
        public void WithExceptionThrown_GetToDoObject_ThrowsException()
        {
            var fakeDb     = A.Fake <IDBInterface>();
            var fakeConfig = A.Fake <IConfiguration>();
            var fakeLogger = A.Fake <ILogger <GetToDoObjectService> >();
            var toDoEntity = new ToDoEntity();

            //A.CallTo(() => fakeDb.Read<ToDoEntity>(A<string>._, A<string>._, A<string>._, A<string>._)).Throws<Exception>();

            var sut = new GetToDoObjectService(fakeDb, fakeConfig, fakeLogger);

            //Assert.That(() => sut.GetToDoObject(toDoEntity).Result, Throws.Exception);
        }
Example #21
0
        public ICommandResult Handle(CreateToDoCommands command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Erro, tarefa errada !", command.Notifications));
            }

            var todoapp = new ToDoEntity(command.Title, command.User, command.Date);

            _repository.Create(todoapp);
            return(new GenericCommandResult(true, "Tarefa Salva !", todoapp));
        }
Example #22
0
        public static ToDoEntity GenerateToDoEntity(
            this Faker faker)
        {
            var toDoEntity =
                new ToDoEntity
            {
                Id          = Guid.NewGuid(),
                Status      = faker.Random.ArrayElement(new[] { "Pending", "In Progress", "Completed", "Canceled" }),
                Description = faker.Lorem.Paragraph(1),
                CreatedOn   = faker.Date.Recent(10)
            };

            return(toDoEntity);
        }
Example #23
0
        public async Task ExceptionThrown_AddToDoObject_ReturnsNull()
        {
            var fakeDb     = A.Fake <IDBInterface>();
            var fakeConfig = A.Fake <IConfiguration>();
            var fakeLogger = A.Fake <ILogger <AddToDoObjectService> >();
            var toDoEntity = new ToDoEntity();

            //A.CallTo(() => fakeDb.CreateAsync<ToDoEntity>(A<ToDoEntity>._, A<string>._, A<string>._))
            //    .Throws<Exception>();

            //var sut = new AddToDoObjectService(fakeDb, fakeConfig, fakeLogger);

            //var result = await sut.AddToDoObject(toDoEntity);

            //Assert.That(result, Is.Null);
        }
        public Task Handle(CreateToDoCommand message, IMessageHandlerContext context)
        {
            var todoEntity = new ToDoEntity
            {
                DateTimeCreated = DateTime.Now,
                Id                = message.Id,
                UserId            = message.UserId,
                Title             = message.Title,
                Description       = message.Description,
                IsCompleted       = false,
                DateTimeCompleted = null
            };

            _toDoRepository.Add(todoEntity);

            return(Task.CompletedTask);
        }
Example #25
0
        public static ToDoEntity GenerateToDoEntity(
            this Faker faker)
        {
            var id =
                Guid.NewGuid().ToString();

            var toDoEntity =
                new ToDoEntity
            {
                Id          = id,
                ToDoId      = id,
                Status      = faker.Random.ArrayElement(new[] { "Pending", "In Progress", "Completed", "Canceled" }),
                Description = faker.Lorem.Paragraph(1)
            };

            return(toDoEntity);
        }
        public async Task <IActionResult> PostAsync(string userId, ToDoEntity todo, CancellationToken cancellationToken)
        {
            await Task.CompletedTask;

            if (string.IsNullOrWhiteSpace(todo?.Content))
            {
                return(this.BadRequest());
            }

            todo.Id           = Guid.NewGuid().ToString();
            todo.UserId       = userId;
            todo.CreationDate = DateTimeOffset.Now;

            this.DataContext.ToDos.Add(todo);
            await this.DataContext.SaveChangesAsync(cancellationToken);

            return(this.Ok(todo));
        }
Example #27
0
        public async Task <T> AddToDoObject <T>(ToDoEntity toDoEntity)
            where T : class
        {
            ToDoEntity result = null;

            try
            {
                result = await _dBInterface.CreateAsync <ToDoEntity>(toDoEntity);

                _logger.LogInformation("Successfully created new ToDoObject");
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to create the ToDoObject", ex);
            }

            return(result as T);
        }
Example #28
0
        public async Task WithValidObject_GetToDoObject_ReturnsObject()
        {
            var fakeDb     = A.Fake <IDBInterface>();
            var fakeConfig = A.Fake <IConfiguration>();
            var fakeLogger = A.Fake <ILogger <GetToDoObjectService> >();
            var toDoEntity = new ToDoEntity();

            //A.CallTo(() => fakeDb.Read<ToDoEntity>(A<string>._, A<string>._, A<string>._, A<string>._))
            //.Returns(new ToDoEntity("userId", "title") { Description = "My First To Do Object" });

            //var sut = new GetToDoObjectService(fakeDb, fakeConfig, fakeLogger);

            //var toDoObject = await sut.GetToDoObject(toDoEntity);
            //var description = toDoObject.Description;

            //Assert.That(toDoObject, Is.Not.Null);
            //Assert.That(description, Is.EqualTo("My First To Do Object"));
            //Assert.That(toDoObject, Is.TypeOf(typeof(ToDoEntity)));
        }
Example #29
0
        public async Task <ToDoEntity> GetToDoObject(GetToDoObjectRequest request)
        {
            ToDoEntity toDoEntity = null;
            var        userId     = request.UserId;
            var        title      = request.Title;

            try
            {
                toDoEntity = await _dBInterface.Read(userId, title);

                _logger.LogInformation("Successfully found ToDoObject");
            }
            catch (Exception ex)
            {
                _logger.LogError("Could not find the given ToDoObject", ex);
            }

            return(toDoEntity);
        }
Example #30
0
 public async Task DeleteAsync(
     ToDoEntity toDoEntity)
 {
     try
     {
         await this.DeleteAsync(toDoEntity, _primaryCloudTable);
     }
     catch
     {
         if (this.AutoFailover)
         {
             await this.DeleteAsync(toDoEntity, _secondaryCloudTable);
         }
         else
         {
             throw;
         }
     }
 }