// Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate // Umbraco.Code.MapAll -Path -VirtualPath -MasterTemplateId -IsMasterTemplate // Umbraco.Code.MapAll -GetFileContent private static void Map(TemplateDisplay source, ITemplate target, MapperContext context) { // don't need to worry about mapping MasterTemplateAlias here; // the template controller handles any changes made to the master template target.Name = source.Name; target.Alias = source.Alias; target.Content = source.Content; target.Id = source.Id; target.Key = source.Key; }
// Umbraco.Code.MapAll private static void Map(ITemplate source, TemplateDisplay target, MapperContext context) { target.Id = source.Id; target.Name = source.Name; target.Alias = source.Alias; target.Key = source.Key; target.Content = source.Content; target.Path = source.Path; target.VirtualPath = source.VirtualPath; target.MasterTemplateAlias = source.MasterTemplateAlias; target.IsMasterTemplate = source.IsMasterTemplate; }
private void AddTemplateToPool(string template, int id) { int x = 3; int y = 3; // Set up the template display: TemplateDisplay td = new TemplateDisplay(); td.SetTemplateInformation(template); if (id > 0) { y = PoolTemplates[id - 1].Bottom + 3; } td.Location = new Point(x, y); td.SkillInfoDisplay = SkillInfoDisplay; PoolTemplates.Add(td); __PoolContainer.Controls.Add(td); // Set up the button display for the template: Button b = new Button(); b.Text = "Save"; b.Visible = false; b.Enabled = false; b.Tag = id; b.Click += SaveTemplateInPool_Click; x += 3 + td.Width; b.Location = new Point(x, y); b.Height = td.Height; b.BackColor = SystemColors.Control; PoolButtons.Add(b); __PoolContainer.Controls.Add(b); }
private void DisplayDraftHand(List <string> hand) { // Clear the current set of draft hand stuff: __DraftHandContainer.Controls.Clear(); DraftHandButtons.Clear(); DraftHandTemplates.Clear(); // OK, let's make some stuff happen! int y = 3; for (int i = 0; i < hand.Count; ++i) { // Set up the template display for this draft hand: TemplateDisplay td = new TemplateDisplay(); td.SetTemplateInformation(hand[i]); td.Location = new Point(3, y); td.SkillInfoDisplay = SkillInfoDisplay; DraftHandTemplates.Add(td); __DraftHandContainer.Controls.Add(td); // Now add the pick buttons: Button b = new Button(); b.Text = "Pick!"; b.Height = td.Height; b.Location = new Point(td.Right + 3, y); b.Tag = i; b.Click += PickTemplate_Click; b.BackColor = SystemColors.Control; DraftHandButtons.Add(b); __DraftHandContainer.Controls.Add(b); // Increment y: y += 3 + td.Height; } }
/// <summary> /// Saves the data type /// </summary> /// <param name="display"></param> /// <returns></returns> public TemplateDisplay PostSave(TemplateDisplay display) { //Checking the submitted is valid with the Required attributes decorated on the ViewModel if (ModelState.IsValid == false) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (display.Id > 0) { // update var template = Services.FileService.GetTemplate(display.Id); if (template == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var changeMaster = template.MasterTemplateAlias != display.MasterTemplateAlias; var changeAlias = template.Alias != display.Alias; Mapper.Map(display, template); if (changeMaster) { if (string.IsNullOrEmpty(display.MasterTemplateAlias) == false) { var master = Services.FileService.GetTemplate(display.MasterTemplateAlias); if (master == null || master.Id == display.Id) { template.SetMasterTemplate(null); } else { template.SetMasterTemplate(master); //After updating the master - ensure we update the path property if it has any children already assigned var templateHasChildren = Services.FileService.GetTemplateDescendants(display.Id); foreach (var childTemplate in templateHasChildren) { //template ID to find var templateIdInPath = "," + display.Id + ","; if (string.IsNullOrEmpty(childTemplate.Path)) { continue; } //Find position in current comma separate string path (so we get the correct children path) var positionInPath = childTemplate.Path.IndexOf(templateIdInPath) + templateIdInPath.Length; //Get the substring of the child & any children (descendants it may have too) var childTemplatePath = childTemplate.Path.Substring(positionInPath); //As we are updating the template to be a child of a master //Set the path to the master's path + its current template id + the current child path substring childTemplate.Path = master.Path + "," + display.Id + "," + childTemplatePath; //Save the children with the updated path Services.FileService.SaveTemplate(childTemplate); } } } else { //remove the master template.SetMasterTemplate(null); } } Services.FileService.SaveTemplate(template); if (changeAlias) { template = Services.FileService.GetTemplate(template.Id); } Mapper.Map(template, display); } else { //create ITemplate master = null; if (string.IsNullOrEmpty(display.MasterTemplateAlias) == false) { master = Services.FileService.GetTemplate(display.MasterTemplateAlias); if (master == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } } // we need to pass the template name as alias to keep the template file casing consistent with templates created with content // - see comment in FileService.CreateTemplateForContentType for additional details var template = Services.FileService.CreateTemplateWithIdentity(display.Name, display.Name, display.Content, master); Mapper.Map(template, display); } return(display); }