예제 #1
0
        /// <summary>
        /// 添加项目原料
        /// </summary>
        /// <param name="request"></param>
        public void AddMaterial(AddProjectMaterialRequest request)
        {
            Project model = this._projectRepository.FindBy(request.ProjectId);

            if (model == null)
            {
                throw new EntityIsInvalidException <string>(request.ProjectId.ToString());
            }
            Product product = this._productRepository.FindBy(request.ProductId);

            if (model == null)
            {
                throw new EntityIsInvalidException <string>(request.ProductId.ToString());
            }
            Users createUser = this._usersRepository.FindBy(request.CreateUserId);

            if (createUser == null)
            {
                throw new EntityIsInvalidException <string>(request.CreateUserId.ToString());
            }

            ProjectMaterial material = new ProjectMaterial(model, product, request.Qty, createUser);

            model.AddMaterial(material);

            this._projectRepository.Add(model);
            this._uow.Commit();
        }
예제 #2
0
 public virtual void AddMaterial(ProjectMaterial model)
 {
     if (this.Material == null)
     {
         this.Material = new List <ProjectMaterial>()
         {
         };
     }
     this.Material.Add(model);
 }
        public void AddProjectMaterial(AddProjectMaterialRequest request)
        {
            ProjectMaterial model = this._projectMaterialRepository.FindBy(request.Id);

            if (model == null)
            {
                throw new EntityIsInvalidException <string>(request.Id.ToString());
            }
            this._projectMaterialRepository.Add(model);
            this._uow.Commit();
        }
        public void RemoveProjectMaterial(int id)
        {
            ProjectMaterial model = this._projectMaterialRepository.FindBy(id);

            if (model == null)
            {
                throw new EntityIsInvalidException <string>(id.ToString());
            }
            this._projectMaterialRepository.Remove(model);
            this._uow.Commit();
        }
예제 #5
0
        private void UpdateProjectMaterials(string[] selectedMaterials, Project projectToUpdate)
        {
            if (selectedMaterials == null)
            {
                projectToUpdate.ProjectMaterials = new List <ProjectMaterial>();
                return;
            }
            var selectedMaterialsHS = new HashSet <string>(selectedMaterials);
            var projMaterials       = new HashSet <int>
                                          (projectToUpdate.ProjectMaterials?.Select(p => p.MaterialReqID));

            foreach (var m in _context.MaterialRequirements
                     .Include(m => m.Inventory)
                     .ThenInclude(i => i.Material))
            {
                if (selectedMaterialsHS.Contains(m.ID.ToString()))
                {
                    if (!projMaterials.Contains(m.ID))
                    {
                        projectToUpdate.ProjectMaterials.Add(new ProjectMaterial
                        {
                            MaterialReqID = m.ID,
                            ProjectID     = projectToUpdate.ID
                        });
                    }
                }
                else
                {
                    if (projMaterials.Contains(m.ID))
                    {
                        ProjectMaterial materialToRemove = projectToUpdate.ProjectMaterials.SingleOrDefault(p => p.MaterialReqID == m.ID);
                        _context.Remove(materialToRemove);
                    }
                }
            }
        }
예제 #6
0
 public static ProjectMaterialView ConvertToProjectMaterialView(this ProjectMaterial model)
 {
     return(Mapper.Map <ProjectMaterial, ProjectMaterialView>(model));
 }