public Response UpdateTemplate(TemplateApiModel model)
        {
            try
            {
                // kiểm tra thông tin truyền vào.
                var form = HttpContext.Request.Form;
                switch (model.Command)
                {
                case "UpdateInfoItemDynamic":
                    UpdateInfoItemDynamic(model, form);
                    break;

                case "UpdateInfoStatic":
                    #region UpdateInfoStatic
                    UpdateInfoStatic(model, form);
                    #endregion
                    break;

                case "AddNewItemDynamic":
                    AddNewItemDynamic(model);
                    break;

                default: break;
                }
                _logs.WriteLogsInfo(Newtonsoft.Json.JsonConvert.SerializeObject(model) + "\r\n" +
                                    Newtonsoft.Json.JsonConvert.SerializeObject(form) + "\r\n");
                return(new Response(200, "Success", model));
            }
            catch (Exception ex)
            {
                _logs.WriteLogsError("UpdateTemplate", Newtonsoft.Json.JsonConvert.SerializeObject(model), ex);
                return(new Response(500, ex.Message, null));
            }
        }
        private void UpdateInfoStatic(TemplateApiModel model, IFormCollection form)
        {
            var item = _templateDetailsService.CreateQuery().Find(o => o.IsDynamic == false &&
                                                                  o.IsBody == false &&
                                                                  o.PartialID == model.PartialID &&
                                                                  o.TemplateID == model.Record)?.SingleOrDefault();

            if (item == null)
            {
                item = new SysTemplateDetailEntity()
                {
                    IsBody      = false,
                    IsDynamic   = false,
                    CModule     = model.CModule,
                    PartialID   = model.PartialID,
                    LayoutName  = model.LayoutName,
                    TemplateID  = model.Record,
                    TypeView    = model.TypeView,
                    ParentID    = string.Empty,
                    PartialView = model.PartialView
                };
                _templateDetailsService.Add(item);
            }
            string detailsTemplateID = item.ID;

            foreach (var key in form.Keys)
            {
                if (model.GetType().GetMember(key).Count() > 0)
                {
                    continue;
                }
                else
                {
                    var itemProperties = _propertyService.CreateQuery().Find(o => o.TemplateDetailID == detailsTemplateID && o.Name == key && o.PartialID == model.PartialID)?.SingleOrDefault();
                    if (itemProperties == null)
                    {
                        itemProperties = new SysTemplatePropertyEntity()
                        {
                            PartialID        = item.PartialID,
                            Name             = key,
                            TemplateDetailID = detailsTemplateID
                        };
                    }
                    var data = form[key];
                    if (!string.IsNullOrEmpty(data))
                    {
                        itemProperties.Value = data;
                        _propertyService.Add(itemProperties);
                    }
                }
            }
        }
        private void AddNewItemDynamic(TemplateApiModel model)
        {
            if (model.CModule.ToLower() == "renderbody")
            {
                model.IsBody = true;
            }
            var item = new SysTemplateDetailEntity()
            {
                CModule    = model.CModule,
                IsBody     = model.IsBody,
                LayoutName = model.LayoutName + "(" + model.Name + ")",
                TypeView   = model.TypeView,
                TemplateID = model.Record,
                IsDynamic  = true,
                ParentID   = model.ParrentLayout,
                PartialID  = Guid.NewGuid().ToString()
            };

            _templateDetailsService.Add(item);
        }
 public Response DeleteDynamicView([FromBody] TemplateApiModel model)
 {
     try
     {
         var item = _templateDetailsService.CreateQuery().Find(o => o.ParentID == model.ParrentLayout &&
                                                               o.PartialID == model.PartialID && o.TemplateID == model.Record)?.SingleOrDefault();
         if (item != null)
         {
             var listPro = _propertyService.GetItemByParentID(item.ID);
             if (listPro != null)
             {
                 _propertyService.RemoveRange(listPro.Select(o => o.ID).ToList());
             }
             _templateDetailsService.Remove(item.ID);
         }
         _logs.WriteLogsInfo(Newtonsoft.Json.JsonConvert.SerializeObject(model));
         return(new Response(200, "Delete Success", null));
     }
     catch (Exception ex)
     {
         _logs.WriteLogsError("DeleteDynamicView", ex);
         return(new Response(500, ex.Message, null));
     }
 }