public void SaveAttribute(FormAttributeEditDto dto) { var entity = new FormAttribute() { Id = dto.Id, Name = dto.Name, Required = dto.Required, TenantId = dto.TenantId, ControlType = dto.ControlType, DisplayOrder = dto.DisplayOrder }; foreach (var i in dto.FormAttributeValueEditDtos) { entity.FormAttributeValues.Add(new FormAttributeValue() { DisplayOrder = i.DisplayOrder, Id = i.Id, Name = i.Name }); } if (entity.Id != 0) { var remove = dbContext.Set <FormAttributeValue>().Where(s => s.FormAttribute.Id == entity.Id).AsNoTracking().ToList().Where(s => !dto.FormAttributeValueEditDtos.Any(v => v.Id == s.Id)); dbContext.RemoveRange(remove); } dbContext.Update(entity); dbContext.SaveChanges(); }
public IActionResult EditFormAttribute(int attributeId) { FormAttributeEditDto data = null; if (attributeId == 0) { data = new FormAttributeEditDto(); } else { data = this.dynamicFormService.GetAttribute(attributeId); } return(View(data)); }
public FormAttributeEditDto GetAttribute(int attributeId) { var entity = this.dbContext.Set <FormAttribute>().Include(s => s.FormAttributeValues).First(s => s.Id == attributeId); var dto = new FormAttributeEditDto() { Id = entity.Id, TenantId = entity.TenantId, ControlType = entity.ControlType, DisplayOrder = entity.DisplayOrder, Name = entity.Name, Required = entity.Required, }; foreach (var i in entity.FormAttributeValues.OrderBy(s => s.DisplayOrder)) { dto.FormAttributeValueEditDtos.Add(new FormAttributeValueEditDto() { DisplayOrder = i.DisplayOrder, Id = i.Id, Name = i.Name, }); } return(dto); }
public IActionResult EditFormAttribute(FormAttributeEditDto data) { data.TenantId = TenantId; dynamicFormService.SaveAttribute(data); return(View(data)); }