public IActionResult Create(Project project)
 {
     if (ModelState.IsValid)
     {
         projectsRepo.Add(project);
         return(RedirectToAction(nameof(Details), new { id = project.ProjectId }));
     }
     return(View(project));
 }
        public async Task <ActionResult <Countries> > AddCountry(AddCountryDto addCountryDto)
        {
            var newcountry = _mapper.Map <Countries>(addCountryDto);

            _projectRepository.Add(newcountry);

            if (await _projectRepository.SaveAllAsync())
            {
                var messageToReturn = _mapper.Map <AddCountryDto>(newcountry);
                return(CreatedAtRoute("GetCountry",
                                      new { countryid = newcountry.Id }, newcountry));
            }
            throw new Exception("Creating the City failed on save");
        }
        public async Task <Unit> Handle(CreateProjectCommand request, CancellationToken cancellationToken)
        {
            var project = Project.CreateProject(
                request.Id,
                request.Description,
                request.RecruitingStatus,
                request.Name,
                request.Type,
                request.Category
                );

            await _repository.Add(project);

            await _repository.SaveChanges();

            return(Unit.Value);
        }
Пример #4
0
        public async Task <IActionResult> Post([FromBody] TProjects project)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                await _projectsRepository.Add(project);

                return(Ok());
            }
            catch (DbUpdateConcurrencyException ex)
            {
                log.WriteLog(ex.ToString(), "ProjectsController.txt");
                return(BadRequest());
            }
        }
Пример #5
0
        public CommonResult Add(AddProjectDto project)
        {
            if (string.IsNullOrEmpty(project.Name))
            {
                return(CommonResult.Failure("Cannot create project without name provided"));
            }
            if (string.IsNullOrEmpty(project.Description))
            {
                return(CommonResult.Failure("Cannot create project without description provided"));
            }
            var existingProject = _projectRepository.GetByName(project.Name);

            if (existingProject != null && existingProject.IsDeleted == false && existingProject.Name == project.Name)
            {
                return(CommonResult.Failure("Project name already exists"));
            }
            _projectRepository.Add(project);
            return(CommonResult.Success());
        }
Пример #6
0
        public async Task <ActionResult <Projects> > AddProject(ProjectDto projectDto)
        {
            //projectDto.IsActive = Convert.ToBoolean(projectDto.IsActive);
            var city = await _projectRepository.GetCityByIdAsync(projectDto.CityId);

            //projectDto.IsActive = true;
            var project = _mapper.Map <Projects>(projectDto);

            project.City = city;
            _projectRepository.Add(project);
            // await _projectRepository.SaveAllAsync();
            // return Ok(project);
            if (await _projectRepository.SaveAllAsync())
            {
                var messageToReturn = _mapper.Map <ProjectDto>(project);
                return(CreatedAtRoute("GetProject",
                                      new { projectid = project.Id }, project));
            }
            throw new Exception("Creating the project failed on save");
        }
        public CommonResult Add(AddProjectDto project)
        {
            if (String.IsNullOrWhiteSpace(project.Name))
            {
                return(CommonResult.Failure("Project name is empty."));
            }
            if (String.IsNullOrWhiteSpace(project.Description))
            {
                return(CommonResult.Failure("Project description is empty."));
            }
            var existingProject = _projectsRepository.GetByName(project.Name);

            if (existingProject != null && !existingProject.IsDeleted && existingProject.Name == project.Name)
            {
                return(CommonResult.Failure("Project name already exists."));
            }

            _projectsRepository.Add(project);

            return(CommonResult.Success());
        }
Пример #8
0
 public string Add(Project model)
 {
     return(projectsRepository.Add(model));
 }