Exemplo n.º 1
0
        public async Task <Project> UpdateProjectAsync(ProjectServiceModel serviceModel)
        {
            var project = await GetProjects().SingleAsync(o => o.Id == serviceModel.Id);

            var newProject = serviceModel.ToEntity();

            _context.Entry(project).CurrentValues.SetValues(newProject);
            _context.Entry(project).Property(o => o.CreateByUserId).IsModified = false;
            _context.Entry(project).Property(o => o.CreateDate).IsModified     = false;

            project.CityId = newProject.CityId;

            foreach (var newDetail in newProject.ProjectDetails)
            {
                var oldDetail = project.ProjectDetails.FirstOrDefault(o => o.Language == newDetail.Language);
                if (oldDetail.Language == newDetail.Language)
                {
                    newDetail.Id = oldDetail.Id;
                    _context.Entry(oldDetail).CurrentValues.SetValues(newDetail);
                }
            }

            _context.TryUpdateProjectBlocks(project.ProjectBlocks, serviceModel.ProjectBlocks, o => o.Id);

            _context.TryUpdateManyToMany(project.EnitityFiles, newProject.EnitityFiles, o => o.FileEntityId);
            _context.TryUpdateManyToMany(project.EntityTaxonomies, newProject.EntityTaxonomies, o => o.TaxonomyId);

            await _context.SaveChangesAsync();

            return(newProject);
        }
Exemplo n.º 2
0
        public async Task <Project> CreateNewProject(ProjectServiceModel serviceModel)
        {
            var newProject = new Project
            {
                Name           = serviceModel.Name,
                BudgetMin      = serviceModel.BudgetMin,
                BudgetMax      = serviceModel.BudgetMax,
                CreateByUserId = serviceModel.User.Id,
                Details        = new List <ProjectDetail>()
                {
                    serviceModel.Detail
                },
                EntityFiles      = serviceModel.GetEntityFiles(),
                EntityTaxonomies = new List <ProjectTaxonomy>(
                    serviceModel.TaxonomyIds.Select(taxonomyId => new ProjectTaxonomy {
                    TaxonomyId = taxonomyId
                })),
                CityId        = serviceModel.CityId,
                ProjectBlocks = serviceModel.ProjectBlocks
            };

            var add = await _context.Project.AddAsync(newProject);

            _context.SaveChanges();

            return(add.Entity);
        }
Exemplo n.º 3
0
        public IActionResult Create(CreateProjectViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!employeeDataService.Exists(model.ProjectManagerNick))
                {
                    ModelState.AddModelError("ProjectManagerNick", "Project Manager Nick is not valid");

                    return(View(model));
                }

                var companyId = userManager.GetUserAsync(this.User).Result.CompanyId;


                var project = new ProjectServiceModel
                {
                    Name           = model.Name,
                    Description    = model.Description,
                    StartDate      = model.StartDate,
                    EndDate        = model.EndDate,
                    CompanyId      = companyId,
                    ProjectManager = employeeDataService.FindByNickname(model.ProjectManagerNick)
                };

                projectDataService.Create(project);

                return(RedirectToAction("AllProjects", "Project"));
            }

            return(View(model));
        }
        public async Task <BaseJsonResult> UpdateProject([FromBody] ProjectViewModel model)
        {
            var projectServiceModel = ProjectServiceModel.FromViewModel(model);

            projectServiceModel.User = CurrentUser;

            await _projectService.UpdateProjectAsync(projectServiceModel);

            return(new BaseJsonResult(Omi.Base.Properties.Resources.POST_SUCCEEDED, model.ProjectId));
        }
        public async Task <BaseJsonResult> CreateNewProject([FromBody] ProjectViewModel viewModel)
        {
            var serviceModel = ProjectServiceModel.FromViewModel(viewModel);

            serviceModel.User = CurrentUser;

            var newProject = await _projectService.CreateNewProject(serviceModel);

            return(new BaseJsonResult(Omi.Base.Properties.Resources.POST_SUCCEEDED, newProject.Id));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Edits a project
        /// </summary>
        /// <param name="model">ProjectServiceModel which is a DTO which contains the needed info for this operations</param>
        public void Edit(ProjectServiceModel model)
        {
            var project = data.Projects.Where(p => p.Id == model.Id).FirstOrDefault();

            project.Name         = model.Name;
            project.Description  = model.Description;
            project.StartDate    = model.StartDate;
            project.EndDate      = model.EndDate;
            project.IsCompleated = model.IsCompleated;

            data.SaveChanges();
        }
Exemplo n.º 7
0
        public async Task <Project> UpdateProjectAsync(ProjectServiceModel serviceModel)
        {
            var project = await GetProjects().SingleAsync(o => o.Id == serviceModel.Id);

            var newProject = serviceModel.ToEntity();

            _context.Entry(project).CurrentValues.SetValues(newProject);
            _context.Entry(project).Property(o => o.CreateByUserId).IsModified = false;
            _context.Entry(project).Property(o => o.CreateDate).IsModified     = false;

            project.CityId = newProject.CityId;

            foreach (var newDetail in newProject.Details)
            {
                var oldDetail = project.Details.FirstOrDefault(o => o.Language == newDetail.Language);
                if (oldDetail.Language == newDetail.Language)
                {
                    newDetail.Id = oldDetail.Id;
                    _context.Entry(oldDetail).CurrentValues.SetValues(newDetail);
                }
            }

            _context.TryUpdateProjectBlocks(project.ProjectBlocks, serviceModel.ProjectBlocks, o => o.Id);

            var packageSet = _context.Set <Package>();

            foreach (var roomtype in project.ProjectBlocks)
            {
                foreach (var roomLayout in roomtype.Children)
                {
                    foreach (var roomPerspective in roomLayout.Children)
                    {
                        if (roomPerspective.PackageId != default)
                        {
                            var package = packageSet.Find(roomPerspective.PackageId);
                            var entry   = _context.Entry(package);
                            entry.Property(o => o.ProjectBlockId).CurrentValue = roomPerspective.Id;
                        }
                    }
                }
            }

            _context.TryUpdateManyToMany(project.EntityFiles, newProject.EntityFiles, o => o.FileEntityId);
            _context.TryUpdateManyToMany(project.EntityTaxonomies, newProject.EntityTaxonomies, o => o.TaxonomyId);

            await _context.SaveChangesAsync();

            return(newProject);
        }
Exemplo n.º 8
0
        public IActionResult Edit(EditViewModel model)
        {
            var serviceModel = new ProjectServiceModel
            {
                Id           = model.Id,
                Name         = model.Name,
                Description  = model.Description,
                StartDate    = model.StartDate,
                EndDate      = model.EndDate,
                IsCompleated = model.IsCompleated
            };

            projectDataService.Edit(serviceModel);

            return(RedirectToAction("AllProjects", "Project"));
        }
        public void DoesCreateWorks()
        {
            var options = new DbContextOptionsBuilder <MDManagementDbContext>()
                          .UseInMemoryDatabase(databaseName: "testDb")
                          .Options;

            using (var dbContext = new MDManagementDbContext(options))
            {
                var userManager = new Mock <UserManager <Employee> >().Object;
                IJobTitleDataService jobTitleService = new JobTittleDataServie(dbContext);
                ICompanyDataService  companyService  = new CompanyDataSerive(dbContext);
                IEmployeeDataService employeeService = new EmployeeDataService(dbContext, jobTitleService, companyService, userManager);
                IProjectDataService  projectService  = new ProjectDataService(dbContext, employeeService);

                var modelService = new ProjectServiceModel
                {
                    Name        = "AI",
                    Description = "nope",
                };

                Assert.AreEqual("AI", dbContext.Projects.FirstOrDefault().Name);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a project
        /// </summary>
        /// <param name="model">Project name</param>
        public void Create(ProjectServiceModel model)
        {
            var project = new Project
            {
                Name        = model.Name,
                Description = model.Description,
                StartDate   = model.StartDate,
                EndDate     = model.EndDate,
                CompanyId   = model.CompanyId,
                ProjectCode = $"#{DateTime.UtcNow.Day}{DateTime.UtcNow.Hour}{DateTime.UtcNow.Minute}{DateTime.UtcNow.Millisecond}"
            };

            data.Projects.Add(project);

            var employeeProject = new EmployeeProject
            {
                Employee = employeeDataService.FindById(model.ProjectManager).Result,
                Project  = project
            };

            data.EmployeeProjects.Add(employeeProject);

            data.SaveChanges();
        }