Example #1
0
        public JsonResult Create(TemplateDto dto)
        {
            dto.TemplateType = (int)TemplateFlag.ProductList;
            var res = _templateContract.Insert(dto);

            return(Json(res));
        }
Example #2
0
        public Template BuildEntity(TemplateDto dto, IEnumerable <IUmbracoEntity> childDefinitions, Func <File, string> getFileContent)
        {
            var template = new Template(dto.NodeDto.Text, dto.Alias, getFileContent);

            try
            {
                template.DisableChangeTracking();

                template.CreateDate = dto.NodeDto.CreateDate;
                template.Id         = dto.NodeId;
                template.Key        = dto.NodeDto.UniqueId;
                template.Path       = dto.NodeDto.Path;

                template.IsMasterTemplate = childDefinitions.Any(x => x.ParentId == dto.NodeId);

                if (dto.NodeDto.ParentId > 0)
                {
                    template.MasterTemplateId = new Lazy <int>(() => dto.NodeDto.ParentId);
                }

                //on initial construction we don't want to have dirty properties tracked
                // http://issues.umbraco.org/issue/U4-1946
                template.ResetDirtyProperties(false);
                return(template);
            }
            finally
            {
                template.EnableChangeTracking();
            }
        }
Example #3
0
        public void ToEntityPizzaTemplate_NameIsNull_PizzaTemplateDtoIsEqualToPizzaTemplate()
        {
            TemplateDto expected = new TemplateDto(
                "Template",
                700,
                "ImageUrl.png",
                new List <IngredientDto>());

            expected.Ingredients.Add(new IngredientDto(
                                         "Dough",
                                         200,
                                         "Dough.png",
                                         "DoughBase.png",
                                         new CategoryDto(Categories.Dough.ToString()),
                                         5));
            expected.Ingredients.Add(new IngredientDto(
                                         "Bacon",
                                         200,
                                         "Bacon.png",
                                         "BaconBase.png",
                                         new CategoryDto(Categories.Meat.ToString()),
                                         50));

            PizzaTemplate actual = EntityBuilder.ToEntity(expected);

            base.AssertPizzaTemplatesAreEqual(actual, expected);
        }
        public void ToPizzaTemplateDto_NameIsNull_PizzaTemplateDtoIsEqualToPizzaTemplate()
        {
            PizzaTemplate expected = new PizzaTemplate(
                Guid.NewGuid(),
                null,
                "ImageUrl.png",
                700);

            expected.Ingredients.Add(new Ingredient(
                                         Guid.NewGuid(),
                                         "Dough",
                                         200,
                                         "Dough.png",
                                         "DoughBase.png",
                                         Categories.Dough,
                                         5));
            expected.Ingredients.Add(new Ingredient(
                                         Guid.NewGuid(),
                                         "Bacon",
                                         200,
                                         "Bacon.png",
                                         "BaconBase.png",
                                         Categories.Meat,
                                         50));

            TemplateDto actual = DtoBuilder.ToDto(expected);

            base.AssertPizzaTemplatesAreEqual(expected, actual);
        }
Example #5
0
        /// <summary>
        /// Maps from a dto to an ITemplate
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="axisDefinitions">
        /// This is a collection of template definitions ... either all templates, or the collection of child templates and it's parent template
        /// </param>
        /// <returns></returns>
        private ITemplate MapFromDto(TemplateDto dto, IUmbracoEntity[] axisDefinitions)
        {
            var factory  = new TemplateFactory();
            var template = factory.BuildEntity(dto, axisDefinitions, file => GetFileContent((Template)file, false));

            if (dto.NodeDto.ParentId > 0)
            {
                var masterTemplate = axisDefinitions.FirstOrDefault(x => x.Id == dto.NodeDto.ParentId);
                if (masterTemplate != null)
                {
                    template.MasterTemplateAlias = masterTemplate.Name;
                    template.MasterTemplateId    = new Lazy <int>(() => dto.NodeDto.ParentId);
                }
            }

            // get the infos (update date and virtual path) that will change only if
            // path changes - but do not get content, will get loaded only when required
            GetFileContent(template, true);

            //on initial construction we don't want to have dirty properties tracked
            // http://issues.umbraco.org/issue/U4-1946
            template.ResetDirtyProperties(false);

            return(template);
        }
        public static Template BuildEntity(IShortStringHelper shortStringHelper, TemplateDto dto, IEnumerable <IUmbracoEntity> childDefinitions, Func <File, string?> getFileContent)
        {
            var template = new Template(shortStringHelper, dto.NodeDto.Text, dto.Alias, getFileContent);

            try
            {
                template.DisableChangeTracking();

                template.CreateDate = dto.NodeDto.CreateDate;
                template.Id         = dto.NodeId;
                template.Key        = dto.NodeDto.UniqueId;
                template.Path       = dto.NodeDto.Path;

                template.IsMasterTemplate = childDefinitions.Any(x => x.ParentId == dto.NodeId);

                if (dto.NodeDto.ParentId > 0)
                {
                    template.MasterTemplateId = new Lazy <int>(() => dto.NodeDto.ParentId);
                }

                // reset dirty initial properties (U4-1946)
                template.ResetDirtyProperties(false);
                return(template);
            }
            finally
            {
                template.EnableChangeTracking();
            }
        }
Example #7
0
        public void ToEntityPizzaTemplate_PizzaTemplateIsEmpty_PizzaTemplateDtoIsEqualToPizzaTemplate()
        {
            TemplateDto   expected = new TemplateDto();
            PizzaTemplate actual   = EntityBuilder.ToEntity(expected);

            base.AssertPizzaTemplatesAreEqual(actual, expected);
        }
Example #8
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            TemplateDto dto = (TemplateDto)context["TemplateDto"];

            TemplateDto.main_TemplatesRow row = null;

            if (dto.main_Templates.Count > 0)
            {
                row = dto.main_Templates[0];
            }
            else
            {
                row = dto.main_Templates.Newmain_TemplatesRow();
                row.ApplicationId = mc.CmsConfiguration.Instance.ApplicationId;
            }

            row.Name         = Name.Text;
            row.FriendlyName = FriendlyName.Text;
            row.Path         = Path.Text;
            row.TemplateType = TemplateType.Text;
            row.LanguageCode = LanguageCode;

            if (row.RowState == DataRowState.Detached)
            {
                dto.main_Templates.Rows.Add(row);
            }
        }
        public JsonResult Update(TemplateDto dto)
        {
            dto.TemplateType = (int)TemplateFlag.Article;
            var res = _templateContract.Update(dto);

            return(Json(res));
        }
        public JsonResult Update(TemplateDto dto)
        {
            dto.TemplateType = (int)TemplateFlag.SectionList;
            var res = _TemplateContract.Update(dto);

            return(Json(res));
        }
Example #11
0
        public ActionResult Edit(TemplateFormViewModel model)
        {
            TemplateDto Template = serviceTemplate.GetItem(model.TemplateId);

            try
            {
                if (ModelState.IsValid)
                {
                    Template.TemplateId = model.TemplateId;

                    Template.Name      = model.Name;
                    Template.AdminView = model.AdminView;
                    Template.FrontView = model.FrontView;
                    Template.IsSection = model.IsSection;
                    Template.Active    = model.Active;

                    serviceTemplate.Edit(Template);
                }
                else
                {
                    ModelState.AddModelError("Error", "Algunos datos ingresados no son válidos");
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", "Se ha producido un error: " + ex.Message);
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }
Example #12
0
 public Template CopyFrom(TemplateDto dto)
 {
     this.Name    = dto.Name;
     this.Version = dto.Version;
     BaseCopyFrom <Template>(dto);
     return(this);
 }
        private string GenerateNews(InputDto inputDto, TemplateDto templateDto)
        {
            List <string> rows = new List <string>();

            rows.AddRange(inputDto.News.Split(System.Environment.NewLine.ToCharArray()));
            rows = rows.Where(r => r != string.Empty).ToList();

            StringBuilder newsRowBuilder = new StringBuilder();

            int index = 0;

            for (int i = 0; i < rows.Count; i++)
            {
                index = i + 1;
                string style = string.Empty;
                if (index % 2 == 0)
                {
                    style = oddRowStyle;
                }
                string row = string.Format(templateDto.NewsRowTemplate, style, index.ToString(), rows[i]);
                newsRowBuilder.Append(row);
            }

            string newsScript = string.Format(templateDto.NewsTemplate, newsRowBuilder.ToString());

            return(newsScript);
        }
Example #14
0
        public async Task <JsonResult> PostTemplate(TemplateDto GetTemplate, string datasetsNameForRemove)
        {
            DbCommand UpdateDefaultTemplate = null;

            try
            {
                if (GetTemplate.IsActive)
                {
                    UpdateDefaultTemplate = BusinessLogic.instance.HandleDashboardNReportBl.InActiveAllTemplateAgainstByUserID(GetTemplate.userID);
                    UpdateDefaultTemplate = DataAccess.Instance.HandleTemplatesAction.EndTrans(UpdateDefaultTemplate);
                }
                await Task.Run(() => BusinessLogic.instance.HandleDashboardNReportBl.SaveTemplateCheckStatus(GetTemplate));

                return(Json(new { status = true, msg = "Template has been saved" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception exe)
            {
                if (UpdateDefaultTemplate != null)
                {
                    UpdateDefaultTemplate = DataAccess.Instance.HandleTemplatesAction.CanTrans(UpdateDefaultTemplate);
                }
                return(Json(new { status = false, msg = exe.InnerException.ToString() }, JsonRequestBehavior.AllowGet));
            }
            finally
            {
                if (UpdateDefaultTemplate != null)
                {
                    DataAccess.Instance.HandleTemplatesAction.ClsCon(UpdateDefaultTemplate);
                }
            }
        }
Example #15
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, EventArgs e)
        {
            TemplateDto dto = null;

            if (TemplateId > 0)
            {
                dto = DictionaryManager.GetTemplateDto(TemplateId);
            }
            else
            {
                dto = new TemplateDto();
            }

            // Put a dictionary key that can be used by other tabs
            IDictionary dic = new ListDictionary();

            dic.Add(_TemplateDtoString, dto);

            ViewControl.SaveChanges(dic);

            // Save modifications
            if (dto.HasChanges())
            {
                DictionaryManager.SaveTemplateDto(dto);
            }

            // Call commit changes
            ViewControl.CommitChanges(dic);
        }
Example #16
0
        public JsonResult Update(TemplateDto dto)
        {
            dto.TemplateType = (int)TemplateFlag.Product;
            var result = _templateContract.Update(dto);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #17
0
        public IActionResult Like(TemplateDto post)
        {
            this._postService.Like(post.PostId);
            UserDto user = HttpContext.Session.GetObject <UserDto>("User");

            return(PartialView("PostPartialView", _postService.GetPostList(user)));
        }
Example #18
0
 public TemplateDto CopyTo(TemplateDto dto)
 {
     dto.Name    = this.Name;
     dto.Version = this.Version;
     BaseCopyTo <TemplateDto>(dto);
     return(dto);
 }
        public JsonResult Create(TemplateDto dto)
        {
            dto.TemplateType = (int)TemplateFlag.Section;
            var res = _TemplateContract.Insert(dto);

            return(Json(res));
        }
Example #20
0
        public async Task <IActionResult> UpdateTemplate([FromBody] TemplateDto template)
        {
            var cl     = new TemplateAdminClient(GetBucksApiClient());
            var result = await cl.UpdateTemplate(template);

            return(Ok(result));
        }
        public TemplateDto CreateTemplate(TemplateDto templateDto)
        {
            using (ConsoleRepository)
            {
                var template = ConsoleRepository.Query <Template>().FirstOrDefault(t => t.Title.Equals(templateDto.Title));

                if (template != null)
                {
                    throw new Exception("Template Already Exists");
                }

                var newTemplate = new Template
                {
                    Title = templateDto.Title,
                    Url   = templateDto.Url,
                    IsPageStructureTemplate = templateDto.IsPageStructureTemplate,
                    AfterRenderDomFunction  = templateDto.AfterRenderDomFunction
                };
                ConsoleRepository.Add <Template>(newTemplate);
                ConsoleRepository.SaveChanges();

                templateDto.Id = newTemplate.Id;
            }

            return(templateDto);
        }
Example #22
0
        /// <summary>
        /// Binds the form.
        /// </summary>
        private void BindForm()
        {
            // Bind Meta classes
            MetaClass catalogEntry = MetaClass.Load(CatalogContext.MetaDataContext, "CatalogEntry");

            MetaClassList.Items.Clear();
            if (catalogEntry != null)
            {
                MetaClassCollection metaClasses = catalogEntry.ChildClasses;
                foreach (MetaClass metaClass in metaClasses)
                {
                    MetaClassList.Items.Add(new ListItem(metaClass.FriendlyName, metaClass.Id.ToString()));
                }

                MetaClassList.DataBind();
            }

            // Bind Templates
            TemplateDto templates = DictionaryManager.GetTemplateDto();

            if (templates.main_Templates.Count > 0)
            {
                DataView view = templates.main_Templates.DefaultView;
                view.RowFilter             = "TemplateType = 'entry'";
                DisplayTemplate.DataSource = view;
                DisplayTemplate.DataBind();
            }

            if (CatalogEntryId > 0)
            {
                if (_CatalogEntryDto.CatalogEntry.Count > 0)
                {
                    Name.Text           = _CatalogEntryDto.CatalogEntry[0].Name;
                    AvailableFrom.Value = ManagementHelper.GetUserDateTime(_CatalogEntryDto.CatalogEntry[0].StartDate);
                    ExpiresOn.Value     = ManagementHelper.GetUserDateTime(_CatalogEntryDto.CatalogEntry[0].EndDate);
                    CodeText.Text       = _CatalogEntryDto.CatalogEntry[0].Code;
                    IsActive.IsSelected = _CatalogEntryDto.CatalogEntry[0].IsActive;

                    ManagementHelper.SelectListItem(DisplayTemplate, _CatalogEntryDto.CatalogEntry[0].TemplateName);
                    ManagementHelper.SelectListItem(MetaClassList, _CatalogEntryDto.CatalogEntry[0].MetaClassId);

                    // Bind Sort order
                    foreach (CatalogRelationDto.NodeEntryRelationRow row in _CatalogRelationDto.NodeEntryRelation)
                    {
                        if (row.CatalogEntryId == _CatalogEntryDto.CatalogEntry[0].CatalogEntryId &&
                            row.CatalogId == this.ParentCatalogId &&
                            row.CatalogNodeId == this.ParentCatalogNodeId)
                        {
                            SortOrder.Text = row.SortOrder.ToString();
                        }
                    }
                }
            }
            else
            {
                this.AvailableFrom.Value = ManagementHelper.GetUserDateTime(DateTime.UtcNow);
                this.ExpiresOn.Value     = ManagementHelper.GetUserDateTime(DateTime.UtcNow).AddYears(1);
            }
        }
Example #23
0
        public JsonResult Update(TemplateDto dto)
        {
            dto.TemplateType         = (int)TemplateFlag.Notification;
            dto.templateNotification = _templateContract.View(dto.Id).templateNotification;
            var res = _templateContract.Update(dto);

            return(Json(res));
        }
        public void ToPizzaTemplateDto_PizzaTemplateIsEmpty_PizzaTemplateDtoIsEqualToPizzaTemplate()
        {
            PizzaTemplate expected = new PizzaTemplate();

            TemplateDto actual = DtoBuilder.ToDto(expected);

            base.AssertPizzaTemplatesAreEqual(expected, actual);
        }
Example #25
0
        public override global::System.Data.DataSet Clone()
        {
            TemplateDto cln = ((TemplateDto)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
Example #26
0
        public void Template_CRUD()
        {
            var proxy = new ProxyService <DeviceService>(new DeviceService(new ServiceContext()));

            //arrange
            var dto = testUtil.TemplateDto();

            //Create
            var rpInsert = proxy.RunAsync(x => x.InsertTemplate(dto));

            rpInsert.Wait();
            Assert.True(rpInsert.Result.Data > 0);

            //Read
            long identity = rpInsert.Result.Data;
            var  rpGet    = proxy.RunAsync(x => x.GetTemplate(identity));

            rpGet.Wait();
            Assert.True(rpInsert.Result.Data == rpGet.Result.Data.Id);

            //Update
            var tmpDto = rpGet.Result.Data;

            tmpDto.Name = "Name updated!";
            var rpUpdate = proxy.RunAsync(x => x.UpdateTemplate(tmpDto));

            rpUpdate.Wait();
            var rpUpdateGet = proxy.RunAsync(x => x.GetTemplate(identity));

            rpUpdateGet.Wait();
            Assert.Equal(rpUpdateGet.Result.Data.Name, tmpDto.Name);

            //Delete
            var rpDelete = proxy.RunAsync(x => x.DeleteTemplate(identity));

            rpDelete.Wait();
            var rpDeleteGet = proxy.RunAsync(x => x.GetTemplate(identity));

            rpDeleteGet.Wait();
            Assert.True(rpDeleteGet.Result.Data == null);

            //List
            var queryDto  = new TemplateDto {
            };
            var pagingDto = new PagingDto {
                pageSize = 3, pageNumber = 1
            };
            var rpList = proxy.RunAsync(x => x.ListTemplate(queryDto, pagingDto));//List

            rpList.Wait();
            Assert.True(rpList?.Result.Data != null && rpList.Result.Data.Any());

            //assert

            //cleaup
            var rpHardDelete = proxy.RunAsync(x => x.DeleteHardTemplate(identity));
        }
Example #27
0
        public ActionResult DeleteTemplate(TemplateDto templateDto)
        {
            TemplatesModule.DeleteTemplate(templateDto);

            return(new JsonNetResult
            {
                Data = Json(new { Result = "Successfully Deleted Template" })
            });
        }
Example #28
0
        protected override void PersistUpdatedItem(ITemplate entity)
        {
            EnsureValidAlias(entity);

            //store the changed alias if there is one for use with updating files later
            string originalAlias = entity.Alias;

            if (entity.IsPropertyDirty("Alias"))
            {
                //we need to check what it currently is before saving and remove that file
                ITemplate current = Get(entity.Id);
                originalAlias = current.Alias;
            }

            var template = (Template)entity;

            if (entity.IsPropertyDirty("MasterTemplateId"))
            {
                ITemplate parent = Get(template.MasterTemplateId.Value);
                if (parent != null)
                {
                    entity.Path = string.Concat(parent.Path, ",", entity.Id);
                }
                else
                {
                    //this means that the master template has been removed, so we need to reset the template's
                    //path to be at the root
                    entity.Path = string.Concat("-1,", entity.Id);
                }
            }

            //Get TemplateDto from db to get the Primary key of the entity
            TemplateDto templateDto = Database.SingleOrDefault <TemplateDto>("WHERE nodeId = @Id", new { entity.Id });

            //Save updated entity to db
            template.UpdateDate = DateTime.Now;
            TemplateDto dto = TemplateFactory.BuildDto(template, NodeObjectTypeId, templateDto.PrimaryKey);

            Database.Update(dto.NodeDto);
            Database.Update(dto);

            //re-update if this is a master template, since it could have changed!
            IEnumerable <IUmbracoEntity> axisDefs = GetAxisDefinitions(dto);

            template.IsMasterTemplate = axisDefs.Any(x => x.ParentId == dto.NodeId);

            //now do the file work
            SaveFile((Template)entity, originalAlias);

            entity.ResetDirtyProperties();

            // ensure that from now on, content is lazy-loaded
            if (template.GetFileContent == null)
            {
                template.GetFileContent = file => GetFileContent((Template)file, false);
            }
        }
Example #29
0
        public ActionResult CreateTemplate(TemplateDto templateDto)
        {
            var template = TemplatesModule.CreateTemplate(templateDto);

            return(new JsonNetResult
            {
                Data = Json(template)
            });
        }
 public int DeleteEnumeration(TemplateDto template)
 {
     try {
         return(objDBFrameworkBL.DeleteEnumeration(template));
     } catch (Exception ex) {
         LogUtilities.LogException(ex);
         return(0);
     }
 }
 public TemplateDto ParseTemplateRawText(string sourceText, string relativePath, string name)
 {
     IDictionary<string, IList<string>> attributes;
     string content = WinSSC.Util.MarkdownUtil.ParseMarkdown(sourceText, relativePath, validAttributes, out attributes);
     TemplateDto template = new TemplateDto()
     {
         Name = name,
         Content = content,
         Attributes = attributes
     };
     return template;
 }
        public ActionResult UpdateTemplate(TemplateDto templateDto)
        {
            TemplatesModule.UpdateTemplate(templateDto);

            return new JsonNetResult
            {
                Data = Json(new { Result = "Successfully updated Template Page" })
            };

        }
        public ActionResult CreateTemplate(TemplateDto templateDto)
        {

            var template = TemplatesModule.CreateTemplate(templateDto);

            return new JsonNetResult
            {
                Data = Json(template)
            };

        }
        public ActionResult DeleteTemplate(TemplateDto templateDto)
        {
            TemplatesModule.DeleteTemplate(templateDto);

            return new JsonNetResult
            {
                Data = Json(new { Result = "Successfully Deleted Template" })
            };

        }
        public TemplateDto CreateTemplate(TemplateDto templateDto)
        {
            using (ConsoleRepository)
            {
                var template = ConsoleRepository.Query<Template>().FirstOrDefault(t => t.Title.Equals(templateDto.Title));

                if (template != null) throw new Exception("Template Already Exists");

                var newTemplate = new Template
                {
                    Title = templateDto.Title,
				    Url = templateDto.Url,
				    IsPageStructureTemplate = templateDto.IsPageStructureTemplate,
				    AfterRenderDomFunction = templateDto.AfterRenderDomFunction
                };
                ConsoleRepository.Add<Template>(newTemplate);
                ConsoleRepository.SaveChanges();

                templateDto.Id = newTemplate.Id;
            }

            return templateDto;
        }
        public void UpdateTemplate(TemplateDto templateDto)
        {
            using (ConsoleRepository)
            {

                var template = ConsoleRepository.Query<Template>().FirstOrDefault(t => t.Id == templateDto.Id);

                if (template != null)
                {
                    ConsoleRepository.Attach<Template>(template);

                    template.Title = templateDto.Title;
                    template.Url = templateDto.Url;
                    template.IsPageStructureTemplate = templateDto.IsPageStructureTemplate;
                    template.AfterRenderDomFunction = templateDto.AfterRenderDomFunction ?? string.Empty;
                }

                ConsoleRepository.SaveChanges();
            }
        }
        public void DeleteTemplate(TemplateDto templateDto)
        {
            using (ConsoleRepository)
            {
                var template = ConsoleRepository.Query<Template>().FirstOrDefault(tp => tp.Id == templateDto.Id);

                if (template != null)
                {
                    ConsoleRepository.Attach<Template>(template);
                    ConsoleRepository.Delete<Template>(template);
                    ConsoleRepository.SaveChanges();
                }
            }
        }
        public TemplateDto GetTemplate(int templateId)
        {
            var templateDto = new TemplateDto();

            using (ConsoleRepository)
            {
                var template = ConsoleRepository.Query<Template>()
                    .FirstOrDefault(t => t.Id == templateId);

                if (template == null) return templateDto;

                templateDto.Id = template.Id;
                templateDto.Url = template.Url;
                templateDto.Title = template.Title;
            }

            return templateDto;
        }