Beispiel #1
0
 public JsonResult SaveAsNewBodyTemplate(BodyTemplateManageModel model)
 {
     if (ModelState.IsValid)
     {
         return(Json(_bodyTemplateService.SaveBodyTemplate(model)));
     }
     return(Json(new ResponseModel
     {
         Success = false,
         Message = ModelState.BuildValidationMessages()
     }));
 }
        /// <summary>
        /// Update value for property of model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateBodyTemplateData(XEditableModel model)
        {
            var bodyTemplate = GetById(model.Pk);

            if (bodyTemplate != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(BodyTemplateManageModel))
                    .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase));
                if (property != null)
                {
                    object value = model.Value.ToType(property, WorkContext.CurrentTimezone);

                    #region Validate

                    var manageModel = new BodyTemplateManageModel(bodyTemplate);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

                    if (validationResults.Any())
                    {
                        return(new ResponseModel
                        {
                            Success = false,
                            Message = validationResults.BuildValidationMessages()
                        });
                    }

                    #endregion

                    bodyTemplate.SetProperty(model.Name, value);
                    var response = Update(bodyTemplate);
                    return(response.SetMessage(response.Success
                        ? T("BodyTemplate_Message_UpdateBodyTemplateInfoSuccessfully")
                        : T("BodyTemplate_Message_UpdateBodyTemplateInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("BodyTemplate_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("BodyTemplate_Message_ObjectNotFound")
            });
        }
        /// <summary>
        /// Save online template
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public ResponseModel DownloadedOnlineTemplate(int id, string name)
        {
            var template = GetOnlineTemplate(id);

            if (template != null)
            {
                var model = new BodyTemplateManageModel
                {
                    Name        = name,
                    Description = template.Description,
                    ImageUrl    = template.ImageUrl,
                    Content     = template.Content
                };

                #region Validate

                var validationResults = model.ValidateModel();

                if (validationResults.Any())
                {
                    return(new ResponseModel
                    {
                        Success = false,
                        Message = validationResults.BuildValidationMessages()
                    });
                }

                #endregion

                var response = SaveBodyTemplate(model);

                return(response.SetMessage(response.Success
                    ? T("BodyTemplate_Message_DownloadOnlineBodyTemplateSuccessfully")
                    : T("BodyTemplate_Message_DownloadOnlineBodyTemplateFailure")));
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("BodyTemplate_Message_OnlineTemplateNotFound")
            });
        }
Beispiel #4
0
        public ActionResult Create(BodyTemplateManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _bodyTemplateService.SaveBodyTemplate(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    switch (submit)
                    {
                    case SubmitType.Save:
                        return(RedirectToAction("Index"));

                    default:
                        return(RedirectToAction("Edit", new { id = (int)response.Data }));
                    }
                }
            }
            return(View(model));
        }
        /// <summary>
        /// Save BodyTemplate
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveBodyTemplate(BodyTemplateManageModel model)
        {
            ResponseModel response;
            var           bodyTemplate = GetById(model.Id);

            if (bodyTemplate != null)
            {
                bodyTemplate.Name        = model.Name;
                bodyTemplate.ImageUrl    = model.ImageUrl;
                bodyTemplate.Description = model.Description;
                bodyTemplate.Content     = model.Content;
                response = Update(bodyTemplate);
                return(response.SetMessage(response.Success
                    ? T("BodyTemplate_Message_UpdateSuccessfully")
                    : T("BodyTemplate_Message_UpdateFailure")));
            }
            Mapper.CreateMap <BodyTemplateManageModel, BodyTemplate>();
            bodyTemplate = Mapper.Map <BodyTemplateManageModel, BodyTemplate>(model);
            response     = Insert(bodyTemplate);
            return(response.SetMessage(response.Success
                ? T("BodyTemplate_Message_CreateSuccessfully")
                : T("BodyTemplate_Message_CreateFailure")));
        }
Beispiel #6
0
        public ActionResult Edit(BodyTemplateManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _bodyTemplateService.SaveBodyTemplate(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    switch (submit)
                    {
                    case SubmitType.Save:
                        if (!string.IsNullOrEmpty(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        return(RedirectToAction("Index"));

                    default:
                        return(RedirectToAction("Edit", new { id = model.Id, returnUrl }));
                    }
                }
            }
            return(View(model));
        }