private string GenerateConsumeEntity(ParseAction action) { ConsumeEntity consume = (ConsumeEntity)action; if (consume.Property.IsPlural) { return(Format.CSharp.EntityProperty(consume.Property) + " = Many<" + Format.CSharp.Type(consume.Entity) + ">(" + this.GenerateConsumeSingleEntity(consume, true, true) + ");"); } return(this.GenerateConsumeSingleEntity(consume) + ";"); }
private string GenerateConsumeSingleEntity(ConsumeEntity consume, bool withoutAssignment = false, bool withoutExecution = false) { // if the referenced Entity is Virtual and is an Extractor, consume it // directly if (consume.Entity.IsVirtual && consume.Entity.ParseAction is ConsumePattern) { string code = this.GenerateConsumePattern( Format.CSharp.Class(consume.Entity), ((ConsumePattern)consume.Entity.ParseAction).Pattern ); return(withoutAssignment ? code : this.WrapAssignment(consume, code)); } // simple case, dispatch to Parse<Entity> string code2 = "Parse" + Format.CSharp.Class(consume.Entity) + (withoutExecution ? "" : "()"); return(withoutAssignment ? code2 : this.WrapAssignment(consume, code2)); }
public ActionResult Create(ConsumeEntity entity) { try { entity.UserId = CurrentUser().UserId; entity.CreateTime = DateTime.Now; var success = _customer.Add(entity).Result > 0; if (success) { return(RedirectToAction(nameof(Index), new { UserId = CurrentUser().UserId })); } else { ModelState.AddModelError("Error", "添加失败"); } } catch (Exception ex) { logger.Error(ex); ModelState.AddModelError("Error", ex.Message); } return(View(entity)); }