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())); }
public IActionResult CreateOptionSet() { EditOptionSetModel model = new EditOptionSetModel { SolutionId = SolutionId.Value }; return(View(model)); }
public IActionResult EditOptionSet(Guid id) { EditOptionSetModel model = new EditOptionSetModel(); if (!id.Equals(Guid.Empty)) { var entity = _optionSetFinder.FindById(id); if (entity != null) { entity.CopyTo(model); model.Details = entity.Items.OrderBy(x => x.DisplayOrder).ToList(); return(View(model)); } } return(NotFound()); }
public IActionResult CreateOptionSet(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"])); } Schema.Domain.OptionSet os = new Schema.Domain.OptionSet(); os.OptionSetId = Guid.NewGuid(); os.Name = model.Name; os.IsPublic = true; os.SolutionId = model.SolutionId; os.CreatedBy = CurrentUser.SystemUserId; List <Schema.Domain.OptionSetDetail> details = new List <Schema.Domain.OptionSetDetail>(); int i = 0; foreach (var item in model.OptionSetName) { if (item.IsEmpty()) { continue; } Schema.Domain.OptionSetDetail osd = new Schema.Domain.OptionSetDetail(); osd.OptionSetDetailId = Guid.NewGuid(); osd.OptionSetId = os.OptionSetId; osd.Name = item; osd.Value = model.OptionSetValue[i]; osd.IsSelected = model.IsSelectedOption[i]; osd.DisplayOrder = i; details.Add(osd); i++; } os.Items = details; _optionSetCreater.Create(os); return(CreateSuccess(new { id = os.OptionSetId })); } return(CreateFailure(GetModelErrors())); }