Ejemplo n.º 1
0
        public IActionResult EditOptionSet(EditOptionSetModel model)
        {
            if (ModelState.IsValid)
            {
                bool hasDupName = model.OptionSetName.GroupBy(x => x).Where(g => g.Count() > 1).Count() > 0;
                if (hasDupName)
                {
                    return(JError(T["validation_name_duplicated"]));
                }
                bool hasDupVal = model.OptionSetValue.GroupBy(x => x).Where(g => g.Count() > 1).Count() > 0;
                if (hasDupVal)
                {
                    return(JError(T["validation_value_duplicated"]));
                }
                var entity  = _optionSetFinder.FindById(model.OptionSetId);
                var details = entity.Items;
                model.CopyTo(entity);
                entity.IsPublic = true;
                _optionSetUpdater.Update(entity);
                int i = 0;
                foreach (var item in model.OptionSetName)
                {
                    if (item.IsEmpty())
                    {
                        continue;
                    }
                    Guid detailid = model.DetailId[i];
                    Schema.Domain.OptionSetDetail osd = new Schema.Domain.OptionSetDetail();
                    osd.OptionSetId  = entity.OptionSetId;
                    osd.Name         = item;
                    osd.Value        = model.OptionSetValue[i];
                    osd.IsSelected   = model.IsSelectedOption[i];
                    osd.DisplayOrder = i;
                    if (detailid.Equals(Guid.Empty))
                    {
                        osd.OptionSetDetailId = Guid.NewGuid();
                        _optionSetDetailCreater.Create(osd);
                    }
                    else
                    {
                        osd.OptionSetDetailId = detailid;
                        _optionSetDetailUpdater.Update(osd);
                        details.Remove(details.Find(n => n.OptionSetDetailId == detailid));
                    }

                    i++;
                }
                //delete lost detail
                if (details.NotEmpty())
                {
                    var lostid = details.Select(n => n.OptionSetDetailId).ToList();
                    _optionSetDetailDeleter.DeleteById(lostid.ToArray());
                }

                return(UpdateSuccess(new { id = entity.OptionSetId }));
            }
            return(UpdateFailure(GetModelErrors()));
        }
Ejemplo n.º 2
0
 public bool Import(Guid solutionId, IList <Domain.OptionSet> optionSets)
 {
     if (optionSets.NotEmpty())
     {
         foreach (var item in optionSets)
         {
             foreach (var d in item.Items)
             {
                 d.OptionSetId = item.OptionSetId;
             }
             var entity = _optionSetFinder.FindById(item.OptionSetId);
             if (entity != null)
             {
                 item.CreatedBy      = _appContext.GetFeature <ICurrentUser>().SystemUserId;
                 item.CreatedOn      = DateTime.Now;
                 item.SolutionId     = solutionId;
                 item.OrganizationId = _appContext.OrganizationId;
                 _optionSetUpdater.Update(item);
                 //_optionSetDetailService.DeleteByParentId(entity.OptionSetId);
                 //_optionSetDetailService.CreateMany(item.Items);
                 foreach (var d in item.Items)
                 {
                     var dd = _optionSetDetailFinder.Find(x => x.OptionSetId == item.OptionSetId && x.OptionSetDetailId == d.OptionSetDetailId);
                     if (dd != null)
                     {
                         dd.Name  = d.Name;
                         dd.Value = d.Value;
                         _optionSetDetailUpdater.Update(dd);
                     }
                     else
                     {
                         d.OptionSetId = item.OptionSetId;
                         _optionSetDetailCreater.Create(d);
                     }
                 }
             }
             else
             {
                 item.CreatedBy      = _appContext.GetFeature <ICurrentUser>().SystemUserId;
                 item.CreatedOn      = DateTime.Now;
                 item.SolutionId     = solutionId;
                 item.OrganizationId = _appContext.GetFeature <ICurrentUser>().OrganizationId;
                 _optionSetCreater.Create(item);
                 _optionSetDetailCreater.CreateMany(item.Items);
             }
         }
     }
     return(true);
 }