Exemple #1
0
 public IActionResult CreateSolutionComponent([FromBody] CreateSolutionComponentModel model)
 {
     if (model.SolutionId.Equals(Guid.Empty) || model.ObjectId.IsEmpty())
     {
         return(JError(T["parameter_error"]));
     }
     if (ModelState.IsValid)
     {
         List <SolutionComponent> entities = new List <SolutionComponent>();
         foreach (var item in model.ObjectId)
         {
             if (!item.Equals(Guid.Empty))
             {
                 var comDesc   = ModuleCollection.GetDescriptor(model.ComponentType);
                 var existsCom = _solutionComponentService.Find(n => n.ObjectId == item && n.ComponentType == comDesc.Identity);
                 if (existsCom == null)
                 {
                     SolutionComponent entity = new SolutionComponent
                     {
                         ComponentType = comDesc.Identity,
                         CreatedBy     = CurrentUser.SystemUserId,
                         ObjectId      = item,
                         SolutionId    = model.SolutionId
                     };
                     entities.Add(entity);
                 }
             }
         }
         if (entities.NotEmpty())
         {
             _solutionComponentService.CreateMany(entities);
             return(JOk(T["added_success"]));
         }
     }
     return(JError(T["added_error"] + ":" + GetModelErrors()));
 }