public Project EditProject(ProjectModel projectModel)
        {
            var project = CastToDbo(projectModel);
            var _projectTechnologies = project.ProjectTechnologies;
            var _projectImagesUrls   = project.ProjectImages;

            project.ProjectTechnologies = null;
            project.ProjectImages       = null;

            var savedProject = _projectRepository.Edit(project);

            if (_projectTechnologies != null)
            {
                foreach (var tech in _projectTechnologies)
                {
                    if (tech.ProjectTechnologyId != 0)
                    {
                        tech.ProjectId = savedProject.ProjectId;
                        _projectTechnologyRepository.Edit(tech);
                    }
                    else
                    {
                        _projectTechnologyRepository.Create(tech);
                    }
                }

                //delete all deleted techs
                var techsToSave = _projectTechnologies.Select(_ => _.ProjectTechnologyId);
                var allTechIds  = _projectTechnologyRepository.GetAllIdsFor(savedProject.ProjectId);
                var idsToDelete = allTechIds.Except(techsToSave).ToList();
                foreach (var id in idsToDelete)
                {
                    var tech = _projectTechnologyRepository.GetByTechnologyId(id);
                    _projectTechnologyRepository.Delete(tech);
                }
            }

            if (_projectImagesUrls != null)
            {
                foreach (var image in _projectImagesUrls)
                {
                    if (image.ProjectImageId != 0)
                    {
                        image.ProjectId = savedProject.ProjectId;
                        _projectImageRepository.Edit(image);
                    }
                    else
                    {
                        _projectImageRepository.Create(image);
                    }
                }
                //delete all deleted techs
                var techsToSave = _projectImagesUrls.Select(_ => _.ProjectImageId);
                var allImageIds = _projectImageRepository.GetAllIdsFor(savedProject.ProjectId);
                var idsToDelete = allImageIds.Except(techsToSave).ToList();
                foreach (var id in idsToDelete)
                {
                    var tech = _projectImageRepository.GetByImageId(id);
                    _projectImageRepository.Delete(tech);
                }
            }

            return(_projectRepository.GetById(project.ProjectId));
        }
 public ProjectImage Edit(ProjectImage image)
 {
     return(_projectImageRepository.Edit(image));
 }