예제 #1
0
 private async Task ProjectRepositoryFillerAsync(ProjectRepository projectRepository, IEnumerable <Project> projects)
 {
     foreach (var project in projects)
     {
         await projectRepository.AddAsync(project);
     }
 }
예제 #2
0
        public async Task <Response> CreateProject(int createdBy, string projectTitle, string projectDescription)
        {
            var response = new Response();

            try
            {
                var user = await _userRepository.GetByIdAsync(createdBy);

                if (user == null)
                {
                    throw new Exception("User do not exist.");
                }

                var project = new Project
                {
                    CreatedBy          = createdBy,
                    ProjectTitle       = projectTitle,
                    ProjectDescription = projectDescription,
                    DateCreated        = DateTime.Now
                };

                await _projectRepository.AddAsync(project);

                response.Success = true;
                return(response);
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Errors.Add(e.Message);
                return(response);
            }
        }
        protected async Task AddAsync()
        {
            var project = await ProjectRepository.AddAsync(ProjectAdd);

            ProjectAdd = new ProjectAdd();
            await NavigationContext.OnMenuUpdatedAsync(Control);

            NavigationManager.NavigateTo("/project/" + project.Id);
        }
예제 #4
0
        public async Task <Project> CreateAsync(Project project, AuthenticatedUser currentUser)
        {
            var dbProject = await projectRepository.AddAsync(ModelsMapper.ConvertProjectServiceModelToDbModel(project));

            var dbUser = await userRepository.FindByIdAsync(currentUser.Id);

            dbUser.ProjectsWithAdminAccess.Add(dbProject.Id.ToString());
            dbUser.ProjectsWithUserAccess.Add(dbProject.Id.ToString());
            await userRepository.UpdateAsync(dbUser);

            return(ModelsMapper.ConvertProjectDbModelToServiceModel(dbProject));
        }
        public async Task <IActionResult> Insert(ProjectInsertViewModel model)
        {
            //زمانی که این پروژه ساخته شده است
            model.Created = DateTime.Now;

            model.UserId = this.UserId;
            // زمانی که از اینجا یک پروژه ایجاد می شود باید وضعیت آن در حالت ادمین کاستومر قرار بگیرد
            model.Status = DataLayer.SSOT.ProjectStatusSSOT.AdminCustomer;

            TempData.AddResult(await _projectRepository.AddAsync(model));

            return(RedirectToAction("Index"));
        }
예제 #6
0
        public async void DeleteByIdAsyncShouldDeleteCorrectProject()
        {
            var options = OverwatchOptionBuilder.CreateBuilderWithName("OverwatchDbDeleteProjectByIdAsync");

            using (var overwatchContext = new OverwatchContext(options))
            {
                var     projectRepository = new ProjectRepository(overwatchContext);
                Project projectToDelete   = _projects.First();
                await projectRepository.AddAsync(projectToDelete);

                var result = await projectRepository.DeleteByIdAsync(projectToDelete.Id);

                Assert.Equal(1, result);
            }
        }
예제 #7
0
        public async void GetByIdAsyncShouldReturnCorrectProject()
        {
            var options = OverwatchOptionBuilder.CreateBuilderWithName("OverwatchDbGetProjectByIdAsync");

            using (var overwatchContext = new OverwatchContext(options))
            {
                var     projectRepository = new ProjectRepository(overwatchContext);
                Project projectToFind     = _projects.First();
                await projectRepository.AddAsync(projectToFind);

                var result = await projectRepository.GetByIdAsync(projectToFind.Id);

                Assert.Equal(projectToFind, result);
            }
        }
        public async Task ProjectRepository_AddAsync_AddsValueToDatabase()
        {
            var expectedCount = ProjectsDbSet.Get().ToList().Count + 1;
            var entityToAdd   = ProjectsDbSet.ProjectBuilder().Create();

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var projectRepository = new ProjectRepository(context);

            await projectRepository.AddAsync(entityToAdd);

            context.Projects.Should().HaveCount(expectedCount);
            var entityFound = await context.Projects.FindAsync(entityToAdd.Id);

            entityFound.Should().BeEquivalentTo(entityToAdd);
            // Assert.That(entityFound, Is.EqualTo(entityToAdd).Using(EqualityComparers.ProjectComparer));
        }
        public async Task AddAsyncTest()
        {
            await using var context = new PMAppDbContext(ContextOptions);
            ProjectRepository repository = new ProjectRepository(context);

            var request = new Project {
                Name = "New project", FromDuration = new DateTime(2020, 5, 18), ToDuration = new DateTime(2021, 1, 15)
            };
            var result = await repository.AddAsync(request);

            Assert.AreEqual(request.Name, result.Name);

            IEnumerable <Project> projects = await repository.GetAllAsync();

            result = projects.FirstOrDefault(x => x.Name == request.Name);
            Assert.NotNull(result);
            Assert.AreEqual(request.Name, result.Name);
        }
예제 #10
0
        public async Task <IActionResult> Put([FromBody] Project editedProject)
        {
            var result = false;

            try
            {
                _log.LogEntrance(nameof(Put), editedProject.ToString());

                var repository = new ProjectRepository(_log, false);

                var exisingProject = await repository.GetById(editedProject.Id);

                if (exisingProject == null)
                {
                    await repository.AddAsync(editedProject);
                }
                else
                {
                    await repository.UpdateAsync(editedProject);
                }

                result = true;

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _log.LogError($"my exception : [{ex.Message}]  [{ex.StackTrace}]");

                return(Ok(false));
            }
            finally
            {
                _log.LogExit(nameof(Add), result.ToString());
            }
        }
        public async Task HandleAsync(CreateProject command)
        {
            var project = await projectFactory.GenerateProject(command);

            await projectRepository.AddAsync(project);
        }