public async Task UpdateFieldTemplate() { var groupShareClient = Helper.GsClient; var tplId = Guid.NewGuid(); var fieldTemplate = new FieldTemplate { Name = $"{tplId}", Description = "test field template", FieldTemplateId = tplId.ToString(), IsTmSpecific = false, Location = Helper.Organization, OwnerId = Helper.OrganizationId }; var templateId = await groupShareClient.TranslationMemories.CreateFieldTemplate(fieldTemplate); Assert.True(templateId != string.Empty); await groupShareClient.TranslationMemories.UpdateFieldTemplate( templateId, new FieldTemplateRequest { Name = "updated field template" }); var updatedTemplate = await groupShareClient.TranslationMemories.GetFieldTemplateById(templateId); Assert.Equal("updated field template", updatedTemplate.Name); await groupShareClient.TranslationMemories.DeleteFieldTemplate(templateId); }
public async Task <string> CreateFieldTempalate(FieldTemplate fieldTemplate) { var client = await GetGroupShareClient(); var templateId = await client.TranslationMemories.CreateFieldTemplate(fieldTemplate); return(templateId); }
public void FieldDefaultValue() { FieldTemplate template = new FieldTemplate(null, "test", Code.Type("type")); template.DefaultValue = Code.String("default"); FieldWriter writer = new FieldWriter(this.output.Language.CastTo <BaseLanguage>()); writer.Write(template, this.output); Assert.AreEqual("private type test = \"default\";", this.output.ToString()); }
protected virtual void AddConstants(ModelTransferObject model, ClassTemplate classTemplate) { foreach (FieldTransferObject constant in model.Constants) { FieldTemplate fieldTemplate = this.AddField(model, constant, classTemplate).Constant(); if (constant.Default != null) { Type type = constant.Default.GetType(); if (type == typeof(int)) { fieldTemplate.DefaultValue = Code.Number((int)constant.Default); } else if (type == typeof(long)) { fieldTemplate.DefaultValue = Code.Number((long)constant.Default); } else if (type == typeof(short)) { fieldTemplate.DefaultValue = Code.Number((short)constant.Default); } else if (type == typeof(uint)) { fieldTemplate.DefaultValue = Code.Number((uint)constant.Default); } else if (type == typeof(ulong)) { fieldTemplate.DefaultValue = Code.Number((ulong)constant.Default); } else if (type == typeof(ushort)) { fieldTemplate.DefaultValue = Code.Number((ushort)constant.Default); } else if (type == typeof(float)) { fieldTemplate.DefaultValue = Code.Number((float)constant.Default); } else if (type == typeof(double)) { fieldTemplate.DefaultValue = Code.Number((double)constant.Default); } else if (type == typeof(DateTime)) { fieldTemplate.DefaultValue = Code.DateTime((DateTime)constant.Default); } else if (type == typeof(bool)) { fieldTemplate.DefaultValue = Code.Boolean((bool)constant.Default); } else { fieldTemplate.DefaultValue = Code.String(constant.Default.ToString()); } } } }
protected override FieldTemplate AddField(ModelTransferObject model, MemberTransferObject member, ClassTemplate classTemplate) { FieldTemplate fieldTemplate = base.AddField(model, member, classTemplate); if (!fieldTemplate.Name.Equals(member.Name, StringComparison.CurrentCultureIgnoreCase)) { fieldTemplate.WithAttribute("JsonProperty", Code.String(member.Name)); classTemplate.AddUsing("Newtonsoft.Json"); } return(fieldTemplate); }
protected override FieldTemplate AddField(ModelTransferObject model, string name, TypeTransferObject type, ClassTemplate classTemplate, IConfiguration configuration) { FieldTemplate fieldTemplate = base.AddField(model, name, type, classTemplate, configuration); if (!fieldTemplate.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) { fieldTemplate.WithAttribute("JsonProperty", Code.String(name)); classTemplate.AddUsing("Newtonsoft.Json"); } return(fieldTemplate); }
protected override FieldTemplate AddField(ModelTransferObject model, MemberTransferObject member, ClassTemplate classTemplate) { IOptions fieldOptions = this.Options.Get(member); FieldTemplate fieldTemplate = base.AddField(model, member, classTemplate); fieldTemplate.Strict = fieldOptions.Strict; if (fieldTemplate.DefaultValue == null && fieldOptions.Strict && !fieldTemplate.Type.IsNullable) { fieldTemplate.DefaultValue = member.Type.Default; } return(fieldTemplate); }
public Field(FieldTemplate template, ICollection <IFieldGenerator> generators) { Template = template; _pools = new Dictionary <FieldObjType, IFieldPool>(); _portals = template.Portals .Where(kv => kv.Value.Name != "sp" && kv.Value.Name != "tp") .ToDictionary( kv => kv.Value.Name, kv => (IFieldPortal) new FieldPortal(this, kv.Value) ); _generators = generators; }
protected override void OnInit(EventArgs e) { LabelCell.CssClass = "FieldLabel"; if (FieldTemplate != null) { FieldTemplate.InstantiateIn(FieldCell); } ReqVal = new RequiredFieldValidator(); base.OnInit(e); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { FieldTemplate template = (FieldTemplate)fragment; output.If(template.Visibility != Visibility.None).Add(template.Visibility.ToString().ToLower()).Add(" ").EndIf() .If(template.IsStatic).Add("static ").EndIf() .If(template.IsConst).Add("const ").EndIf() .If(template.IsReadonly).Add("readonly ").EndIf() .Add(template.Name) .Add(": ") .Add(template.Type) .If(template.DefaultValue != null).Add(" = ").Add(template.DefaultValue).EndIf() .CloseLine(); }
private async Task <string> CreateFieldTempalate(FieldTemplatesProvider fieldTemplatesProvider) { var newFieldTemplate = new FieldTemplate { OwnerId = TemplateOwnerId.Text, Location = TemplateLocation.Text, Name = TemplateName.Text, Description = "Dev. Testing", IsTmSpecific = false }; var fieldTemplateId = await fieldTemplatesProvider.CreateFieldTempalate(newFieldTemplate); return(fieldTemplateId); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { FieldTemplate template = (FieldTemplate)fragment; output.If(template.Visibility != Visibility.None).Add(template.Visibility.ToString().ToLower()).Add(" ").EndIf() .If(template.IsStatic || template.IsConstant).Add("static ").EndIf() .If(template.IsReadonly || template.IsConstant).Add("readonly ").EndIf() .Add(template.Name) .If(template.IsOptional).Add("?").EndIf() .Add(": ") .Add(template.Type) .If(template.DefaultValue == null && template.Strict && template.Type.IsNullable).Add(" | undefined").EndIf() .If(template.DefaultValue != null && !template.Class.IsInterface).Add(" = ").Add(template.DefaultValue).EndIf() .CloseLine(); }
private async Task <string> CreateFieldTemplate() { var tplId = Guid.NewGuid(); var fieldTemplate = new FieldTemplate { Name = $"field template {tplId}", Description = "test field template", FieldTemplateId = tplId.ToString(), IsTmSpecific = false, Location = Helper.Organization, OwnerId = Helper.OrganizationId }; fieldTemplateId = await gsClient.TranslationMemories.CreateFieldTemplate(fieldTemplate); return(fieldTemplateId); }
protected virtual FieldTemplate AddField(ModelTransferObject model, MemberTransferObject member, ClassTemplate classTemplate) { IOptions fieldOptions = this.Options.Get(member); if (model.Language != null && fieldOptions.Language != null) { this.MapType(model.Language, fieldOptions.Language, member.Type); } this.AddUsing(member.Type, classTemplate, fieldOptions); FieldTemplate fieldTemplate = classTemplate.AddField(member.Name, member.Type.ToTemplate()).Public().FormatName(fieldOptions) .WithComment(member.Comment); if (fieldOptions.WithOptionalProperties) { fieldTemplate.Optional(); } return(fieldTemplate); }
public ActionResult GetFieldTemplate(ClaimFieldTemplate ClaimFieldTemplate, String FieldMode) { //string claimFieldTemplateName = ClaimFieldTemplate.FieldType.TemplateName; //switch (claimFieldTemplateName) //{ // case "ShortText": // break; // case "LongText": // break; // case "Integer": // break; // case "Float": // break; // case "Date": // break; // case "DateTime": // break; // case "DropDown": // break; // case "MultiChoice": // //return RedirectToAction("Edit", "ClaimTemplate", new { @id = claimTempalteID }); // return PartialView("MultiSelectTemplate", new { claimField = ClaimFieldTemplate, FieldMode = FieldMode }); // break; // case "File": // break; // case "Money": // break; // case "Country": // break; // case "Range": // break; // default: // break; //} ViewBag.ClaimFieldTemplateName = ClaimFieldTemplate.FieldType.TemplateName; FieldTemplate FieldTemplate = new FieldTemplate() { ClaimFieldTemplate = ClaimFieldTemplate, FieldMode = FieldMode }; return(View(FieldTemplate)); }
public override IEnumerable <FieldTemplate> GetTemplates() { var templates = new FieldTemplate[] { new PageFieldTemplate(PageTemplateNameConstants.Login) { IndexThePage = false, FieldGroups = new [] { new FieldTemplateFieldGroup() { Id = "General", Collapsed = false, Fields = { SystemFieldDefinitionConstants.Name, SystemFieldDefinitionConstants.Url } }, new FieldTemplateFieldGroup() { Id = "Login", Collapsed = false, Fields = { PageFieldNameConstants.Title, LoginPageFieldNameConstants.RedirectLink, } }, new FieldTemplateFieldGroup() { Id = "ForgotPassword", Collapsed = false, Fields = { LoginPageFieldNameConstants.ForgottenPasswordLink, } } } }, }; return(templates); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { FieldTemplate template = (FieldTemplate)fragment; FieldTemplate lastTemplate = output.LastFragments.FirstOrDefault() as FieldTemplate; if (template.Attributes.Count > 0 || lastTemplate?.Attributes.Count > 0) { output.BreakLine(); } output.Add(template.Attributes) .If(template.Visibility != Visibility.None).Add(template.Visibility.ToString().ToLower()).Add(" ").EndIf() .If(template.IsStatic).Add("static ").EndIf() .If(template.IsConstant).Add("const ").EndIf() .If(template.IsReadonly).Add("readonly ").EndIf() .Add(template.Type).Add(" ") .Add(template.Name) .If(template.DefaultValue != null && !template.Class.IsInterface).Add(" = ").Add(template.DefaultValue).EndIf() .CloseLine(); }
public ActionResult SaveFieldTemplate(int?id) { FieldTemplate model = null; if (id.HasValue) { model = _IFormDesign.GetFieldTemplate(id.Value); if (model == null) { return(Alert("表单模板不存在!")); } } else { model = new FieldTemplate(); } ViewData["GroupId"] = new SelectList(_IFormDesign.GetFieldTemplateGroup(), "Id", "Name", model.GroupId); return(View(model)); }
public async Task CreateFieldTemplate(string templateName) { var groupShareClient = await Helper.GetGroupShareClient(); var fieldTemplate = new FieldTemplate { Name = templateName, Description = "test", FieldTemplateId = Guid.NewGuid().ToString(), IsTmSpecific = false, Location = "/SDL Community Developers", OwnerId = "5bdb10b8-e3a9-41ae-9e66-c154347b8d17" }; var templateId = await groupShareClient.TranslationMemories.CreateFieldTemplate(fieldTemplate); Assert.True(templateId != string.Empty); await groupShareClient.TranslationMemories.DeleteFieldTemplate(templateId); }
public async Task DeleteFieldForTemplate() { var groupShareClient = Helper.GsClient; var templateGuid = Guid.NewGuid(); var fieldTemplate = new FieldTemplate { Name = $"field template - {templateGuid}", Description = "test field template", IsTmSpecific = false, Location = Helper.Organization, OwnerId = Helper.OrganizationId }; var fieldTemplateId = await groupShareClient.TranslationMemories.CreateFieldTemplate(fieldTemplate); var fieldGuid = Guid.NewGuid(); var field = new FieldRequest { Name = fieldGuid.ToString(), Type = FieldRequest.TypeEnum.SingleString, Values = new List <string> { "test", "a", "is", "this" } }; var fieldId = await groupShareClient.TranslationMemories.CreateFieldForTemplate(fieldTemplateId, field); Assert.True(fieldId != string.Empty); var fields = await groupShareClient.TranslationMemories.GetFieldsForTemplate(fieldTemplateId); Assert.True(fields.Count == 1); Assert.True(fields[0].Values.Count == 4); await groupShareClient.TranslationMemories.DeleteFieldForTemplate(fieldTemplateId, fieldId); fields = await groupShareClient.TranslationMemories.GetFieldsForTemplate(fieldTemplateId); Assert.True(fields.Count == 0); await groupShareClient.TranslationMemories.DeleteFieldTemplate(fieldTemplateId); }
public void FieldTemplate_InvalidFieldDecimalPlaces_ThowsException() { // ASSERT: // Field decimal places cannot be less than zero FieldTemplate fieldTemplate = null; try { Debug.WriteLine("Testing field decimal places"); fieldTemplate = new FieldTemplate(fieldName: "TEST", fieldType: FieldType.BinaryNum, startPosition: 1, fieldSize: 1, decimalPlaces: -1); Assert.IsTrue(false, "No exception was thrown"); } catch (ArgumentOutOfRangeException ex) { Debug.WriteLine(ex.Message); } Assert.IsNull(fieldTemplate); }
public void FieldTemplate_InvalidBinaryNumFieldSize_ThowsException() { // ASSERT: // Field BinaryNum field size is expected to be 1, 2 or 4 bytes FieldTemplate fieldTemplate = null; try { Debug.WriteLine("Testing BinaryNum field size"); fieldTemplate = new FieldTemplate(fieldName: "TEST", fieldType: FieldType.BinaryNum, startPosition: 1, fieldSize: 3); Assert.IsTrue(false, "No exception was thrown"); } catch (ArgumentException ex) { Debug.WriteLine(ex.Message); } Assert.IsNull(fieldTemplate); }
public void ShowTestField() { var list = new List <ValueTuple <List <TerrainPointInfo>, Vector3> >(); foreach (var f in FindObjectsOfType <FieldSnapshotComponent>()) { list.Add((FieldTemplate.CreateTerrainPointInfo(f.Range, f.Highest, f.MaterialType, f.Seeds), f.transform.position)); } realizer.ResetField(); foreach (var tuple in list) { realizer.Realize(Vector3.zero, tuple.Item1, tuple.Item2); } foreach (var u in FindObjectsOfType <UnitSnapshotComponent>()) { u.SetHeight(rate); } }
public void FieldTemplate_InvalidFieldStartPosition_ThowsException() { // ASSERT: // Field start position cannot be negative FieldTemplate fieldTemplate = null; try { Debug.WriteLine("Testing field start position"); fieldTemplate = new FieldTemplate(fieldName: "TEST", fieldType: FieldType.String, startPosition: -1, fieldSize: 1); Assert.IsTrue(false, "No exception was thrown"); } catch (ArgumentOutOfRangeException ex) { Debug.WriteLine(ex.Message); } Assert.IsNull(fieldTemplate); }
// TODO: Better physicalspace2d handling public Field(GameStage stage, FieldTemplate template) { _stage = stage; _template = template; _footholds = new PhysicalLineGrid2D <FieldFootholdTemplate>(_template.Bounds, new Size2D(ScreenWidthOffset / 3, ScreenHeightOffset / 3)); _footholds.Insert(_template.Footholds.Values); _objectLock = new object(); _pools = new Dictionary <FieldObjType, IFieldPool>(); var splitRowCount = (template.Bounds.Size.Height + (ScreenHeightOffset - 1)) / ScreenHeightOffset; var splitColCount = (template.Bounds.Size.Width + (ScreenWidthOffset - 1)) / ScreenWidthOffset; _splits = new IFieldSplit[splitRowCount, splitColCount]; for (var row = 0; row < splitRowCount; row++) { for (var col = 0; col < splitColCount; col++) { _splits[row, col] = new FieldSplit(row, col); } } Generators = new List <IFieldGenerator>(); template.Life.ForEach(l => Generators.Add(l.Type switch { FieldLifeType.NPC => new FieldNPCGenerator(l, stage.NPCTemplates.Retrieve(l.TemplateID).Result), FieldLifeType.Monster => l.MobTime > 0 ? new FieldMobTimedGenerator(l, stage.MobTemplates.Retrieve(l.TemplateID).Result) : new FieldMobNormalGenerator(l, stage.MobTemplates.Retrieve(l.TemplateID).Result), _ => throw new NotImplementedException() })
public async Task AddOperations() { var groupShareClient = Helper.GsClient; var tplId = Guid.NewGuid(); var fieldTemplate = new FieldTemplate { Name = $"{tplId}", Description = "test field template", FieldTemplateId = tplId.ToString(), IsTmSpecific = false, Location = Helper.Organization, OwnerId = Helper.OrganizationId }; var templateId = await groupShareClient.TranslationMemories.CreateFieldTemplate(fieldTemplate); Assert.True(templateId != string.Empty); await groupShareClient.TranslationMemories.AddOperationsForFieldTemplate( templateId, new FieldTemplatePatchRequest { Operations = new List <Operation> { new Operation { Path = "/fields", Op = "replace", Value = null } } }); await groupShareClient.TranslationMemories.DeleteFieldTemplate(templateId); }
public ActionResult SaveFieldTemplate(FieldTemplate model) { _IFormDesign.Save <FieldTemplate>(model); return(Alert("数据保存成功!", Url.Action("FieldTemplate"))); }
private void BuildDetail() { // get page width int pageWidth = (int)_rpt.Layout.Width; // get detail section Section section = _rpt.Sections[SectionTypeEnum.Detail]; section.Visible = true; section.Height = DEFFIELDHEIGHT; // build columnar detail if (_btnColumnar.Checked) { // calculate label width int lblWidth = 0; foreach (FieldTemplate ft in _fieldList) { lblWidth = Math.Max(lblWidth, ft._name.Length); } lblWidth *= 1440 * 8 / 72; // << chars to twips (approximation) // add fields Field f; double top = 0; foreach (FieldTemplate ft in _fieldList) { // skip groups if (ft._group) { continue; } // add label // make it overlap the value field horizontally (width = iMax + 100) // so it will be pushed down when (if) the field above grows var field = MakeTextField(BuildName(ft._name, "Lbl"), ft._name, 0, top, lblWidth + 100, DEFFIELDHEIGHT, FieldAlignEnum.LeftTop); section.Fields.Add(field); // add value field field = MakeTextField(BuildName(ft._name, "Ctl"), new ScriptObjectValue() { Expression = ft._name }, lblWidth, top, pageWidth - lblWidth, DEFFIELDHEIGHT, FieldAlignEnum.LeftTop); field.AutoHeight = AutoSizeBehavior.CanGrow; section.Fields.Add(field); // ready for next top += DEFFIELDHEIGHT; } // add line below detail #pragma warning disable CS0618 f = section.Fields.Add("pushLin", null, 0, top + 100, pageWidth, 30); #pragma warning restore CS0618 f.BackColor = Color.Black; //f.BackStyle = BackStyleEnum.Opaque; // always allow this section to grow //section.Height = top + 300; // section.CanGrow = true; section.AutoHeight = AutoSizeBehavior.CanGrow; return; } // build justified detail if (_btnJustified.Checked) { // initialize field rectangle Rectangle rc = Rectangle.Empty; // loop through the fields for (int i = 0; i < _fieldList.Count; i++) { FieldTemplate ft = (FieldTemplate)_fieldList[i]; if (ft._group) { continue; } // get width rc.Width = ft._width; // skip to next line if we have to if (rc.Left > 0 && rc.Right >= pageWidth) { rc.X = 0; rc.Y += rc.Height; } // can't overflow page if (rc.Width > pageWidth) { rc.Width = pageWidth; } // fit last field on a page to right edge if (i == _fieldList.Count - 1) { rc.Width = pageWidth - rc.Left; } else { FieldTemplate ftNext = (FieldTemplate)_fieldList[i + 1]; if (rc.Right + ftNext._width > pageWidth) { rc.Width = pageWidth - rc.Left; } } // compute height for this row if (rc.Left == 0) { rc.Height = DEFFIELDHEIGHT * 2; double x = 0; for (int j = i; j < _fieldList.Count; j++) { FieldTemplate ftRow = (FieldTemplate)_fieldList[j]; x += ftRow._width; if (x > pageWidth) { break; } int lines = (int)(ftRow._fullWid / ftRow._width); int height = 280 * (lines + 1); if (height > rc.Height) { rc.Height = height; } } // sanity on memo fields if (rc.Height > MAXFIELDHEIGHT) { rc.Height = MAXFIELDHEIGHT; } } // add label (fixed height) var field = MakeTextField(BuildName(ft._name, "Lbl"), ft._name, rc.Left, rc.Top, rc.Width, DEFFIELDHEIGHT, FieldAlignEnum.CenterMiddle); field.BackColor = Color.FromArgb(192, 192, 192); field.ForeColor = Color.White; field.Border.Style = C1.Win.C1Document.DashStyle.Solid; field.Border.Width = 30; if (field.Font.Size > 11) { field.Font.Size = 11; // make sure these guys fit!!! } section.Fields.Add(field); // add value field field = MakeTextField(BuildName(ft._name, "Ctl"), new ScriptObjectValue() { Expression = ft._name }, rc.Left, rc.Top + 280, rc.Width, rc.Height - DEFFIELDHEIGHT, FieldAlignEnum.LeftTop); field.MarginLeft = 50; field.Border.Style = C1.Win.C1Document.DashStyle.Solid; field.Border.Color = Color.FromArgb(192, 192, 192); section.Fields.Add(field); // move on to next rc.X += rc.Width; } section.Height = rc.Bottom; return; } // others are all the same (tabular) foreach (FieldTemplate ft in _fieldList) { // skip groups if (ft._group) { continue; } // add calculated field var field = MakeTextField(BuildName(ft._name, "Ctl"), new ScriptObjectValue() { Expression = ft._name }, ft._left, 0, ft._width, DEFFIELDHEIGHT, (IsFieldNumber(ft._name)) ? FieldAlignEnum.RightTop : FieldAlignEnum.LeftTop); field.AutoHeight = ft._canGrow ? AutoSizeBehavior.CanGrow : AutoSizeBehavior.None; section.Fields.Add(field); // if any of the fields can grow, so can the section if (ft._canGrow) { section.AutoHeight = AutoSizeBehavior.CanGrow; } } }
private static void AddField(Snapshot snapshot, Coordinates location) { snapshot.AddEntity(FieldTemplate.CreateFieldEntityTemplate(location, 3000, 500, FieldMaterialType.None)); }
public virtual void Write(EntityFrameworkWriteConfiguration configuration, List <ITransferObject> transferObjects, List <FileTemplate> files) { foreach (EntityFrameworkWriteRepositoryConfiguration repositoryConfiguration in configuration.Repositories) { EntityTransferObject entity = transferObjects.OfType <EntityTransferObject>().FirstOrDefault(x => x.Name == repositoryConfiguration.Entity) .AssertIsNotNull(nameof(repositoryConfiguration.Entity), $"Entity {repositoryConfiguration.Entity} not found. Ensure it is read before."); ClassTemplate repository = files.AddFile(configuration.RelativePath, configuration.AddHeader) .AddNamespace(repositoryConfiguration.Namespace ?? configuration.Namespace) .AddClass(repositoryConfiguration.Name ?? entity.Name + "Repository") .FormatName(configuration) .WithUsing("System.Collections.Generic") .WithUsing("System.Linq"); if (configuration.IsCore) { repository.WithUsing("Microsoft.EntityFrameworkCore"); } else { repository.WithUsing("System.Data.Entity"); } if (!string.IsNullOrEmpty(configuration.Namespace) && !string.IsNullOrEmpty(repositoryConfiguration.Namespace) && configuration.Namespace != repositoryConfiguration.Namespace) { repository.AddUsing(configuration.Namespace); } configuration.Usings.ForEach(x => repository.AddUsing(x)); repositoryConfiguration.Usings.ForEach(x => repository.AddUsing(x)); TypeTemplate modelType = entity.Model.ToTemplate(); FieldTemplate dataSetField = repository.AddField("dataSet", Code.Generic("DbSet", modelType)).Readonly(); FieldTemplate dataContextField = repository.AddField("dataContext", Code.Type("DataContext")).Readonly(); TypeTemplate dataContextType = Code.Type("DataContext"); ConstructorTemplate constructor = repository.AddConstructor(); ParameterTemplate dataContextParameter = constructor.AddParameter(dataContextType, "dataContext", Code.Null()); constructor.Code.AddLine(Code.This().Field(dataContextField).Assign(Code.NullCoalescing(Code.Local(dataContextParameter), Code.New(dataContextType))).Close()) .AddLine(Code.This().Field(dataSetField).Assign(Code.This().Field(dataContextField).GenericMethod("Set", modelType)).Close()); repository.AddMethod("Get", Code.Generic("IQueryable", modelType)) .Code.AddLine(Code.Return(Code.This().Field(dataSetField))); repository.AddMethod("Get", modelType) .WithParameter(Code.Type("params object[]"), "keys") .Code.AddLine(Code.Return(Code.This().Field(dataSetField).Method("Find", Code.Local("keys")))); if (configuration.IsCore) { repository.AddMethod("Add", modelType) .WithParameter(modelType, "entity") .Code.AddLine(Code.Declare(modelType, "result", Code.This().Field(dataSetField).Method("Add", Code.Local("entity")).Property("Entity"))) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()) .AddLine(Code.Return(Code.Local("result"))); repository.AddMethod("Add", Code.Generic("IEnumerable", modelType)) .WithParameter(Code.Generic("IEnumerable", modelType), "entities") .Code.AddLine(Code.Declare(Code.Generic("IEnumerable", modelType), "result", Code.Local("entities").Method("Select", Code.Lambda("x", Code.This().Field(dataSetField).Method("Add", Code.Local("x")).Property("Entity"))).Method("ToList"))) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()) .AddLine(Code.Return(Code.Local("result"))); repository.AddMethod("Update", modelType) .WithParameter(modelType, "entity") .Code.AddLine(Code.Declare(modelType, "result", Code.This().Field(dataSetField).Method("Update", Code.Local("entity")).Property("Entity"))) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()) .AddLine(Code.Return(Code.Local("result"))); repository.AddMethod("Update", Code.Generic("IEnumerable", modelType)) .WithParameter(Code.Generic("IEnumerable", modelType), "entities") .Code.AddLine(Code.Declare(Code.Generic("IEnumerable", modelType), "result", Code.Local("entities").Method("Select", Code.Lambda("x", Code.This().Field(dataSetField).Method("Update", Code.Local("x")).Property("Entity"))).Method("ToList"))) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()) .AddLine(Code.Return(Code.Local("result"))); } else { repository.AddMethod("Add", modelType) .WithParameter(modelType, "entity") .Code.AddLine(Code.Declare(modelType, "result", Code.This().Field(dataSetField).Method("Add", Code.Local("entity")))) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()) .AddLine(Code.Return(Code.Local("result"))); repository.AddMethod("Add", Code.Generic("IEnumerable", modelType)) .WithParameter(Code.Generic("IEnumerable", modelType), "entities") .Code.AddLine(Code.Declare(Code.Generic("IEnumerable", modelType), "result", Code.Local("entities").Method("Select", Code.Lambda("x", Code.This().Field(dataSetField).Method("Add", Code.Local("x")))).Method("ToList"))) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()) .AddLine(Code.Return(Code.Local("result"))); repository.WithUsing("System.Data.Entity.Migrations") .AddMethod("Update", modelType) .WithParameter(modelType, "entity") .Code.AddLine(Code.This().Field(dataSetField).Method("AddOrUpdate", Code.Local("entity")).Close()) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()) .AddLine(Code.Return(Code.Local("entity"))); repository.WithUsing("System.Data.Entity.Migrations") .AddMethod("Update", Code.Generic("IEnumerable", modelType)) .WithParameter(Code.Generic("IEnumerable", modelType), "entities") .Code.AddLine(Code.Declare(Code.Generic("List", modelType), "result", Code.Local("entities").Method("ToList"))) .AddLine(Code.Local("result").Method("ForEach", Code.Lambda("x", Code.This().Field(dataSetField).Method("AddOrUpdate", Code.Local("x")))).Close()) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()) .AddLine(Code.Return(Code.Local("result"))); } //repository.AddMethod("Update", Code.Void()) // .WithParameter(Code.Generic("Delta", modelType), "delta") // .WithParameter(Code.Type("object[]"), "keys") // .Code.AddLine(Code.Declare(modelType, "entity", Code.This().Field(dataSetField).Method("Find", Code.Local("keys")))) // .AddLine(Code.If(Code.Local("entity").Equals().Null(), x => x.Code.AddLine(Code.Throw(Code.Type("InvalidOperationException"), Code.String("Can not find any element with this keys, Use Add(...) method instead"))))) // .AddLine(Code.Local("delta").Method("Patch", Code.Local("entity")).Close()) // .AddLine(Code.This().Method("Update", Code.Local("entity")).Close()) // .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()); repository.AddMethod("Delete", Code.Void()) .WithParameter(modelType, "entity") .Code.AddLine(Code.This().Field(dataSetField).Method("Remove", Code.Local("entity")).Close()) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()); repository.AddMethod("Delete", Code.Void()) .WithParameter(Code.Generic("IEnumerable", modelType), "entities") .Code.AddLine(Code.This().Field(dataSetField).Method("RemoveRange", Code.Local("entities")).Close()) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()); if (configuration.IsCore) { repository.AddMethod("Delete", Code.Void()) .WithParameter(Code.Type("params object[]"), "keys") .Code.AddLine(Code.This().Field(dataSetField).Method("Remove", Code.This().Field(dataSetField).Method("Find", Code.Local("keys"))).Close()) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()); } else { repository.AddMethod("Delete", Code.Void()) .WithParameter(Code.Type("params object[]"), "keys") .Code.AddLine(Code.This().Field(dataSetField).Method("Remove", Code.This().Field(dataSetField).Method("Find", Code.Local("keys"))).Close()) .AddLine(Code.This().Field(dataContextField).Method("SaveChanges").Close()); } //foreach (string key in entity.Keys) //{ // PropertyTransferObject property = entity.Model.Properties.First(x => x.Name.Equals(key, StringComparison.InvariantCultureIgnoreCase)); // delete.AddParameter(property.Type.ToTemplate(), property.Name) // .FormatName(configuration.Language, configuration.FormatNames); //} } }