Ejemplo n.º 1
0
        /// <summary>
        /// Save RSS feed
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveRssFeed(RssFeedManageModel model)
        {
            ResponseModel response;
            var           feed = GetById(model.Id);

            // Edit existed RSS feed
            if (feed != null)
            {
                feed.Name = model.Name;
                feed.Url  = model.Url;

                response = Update(feed);
                return
                    (response.SetMessage(response.Success
                        ? T("RSSFeed_Message_UpdateSuccessfully")
                        : T("RSSFeed_Message_UpdateFailure")));
            }

            // Insert new RSS feed
            Mapper.CreateMap <RssFeedManageModel, RssFeed>();
            feed = Mapper.Map <RssFeedManageModel, RssFeed>(model);

            response = Insert(feed);

            return(response.SetMessage(response.Success
                ? T("RSSFeed_Message_CreateSuccessfully")
                : T("RSSFeed_Message_CreateFailure")));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update RSS feed
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateRssFeedData(XEditableModel model)
        {
            var rssFeed = GetById(model.Pk);

            if (rssFeed != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(RssFeedManageModel))
                    .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 RssFeedManageModel(rssFeed);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

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

                    #endregion

                    rssFeed.SetProperty(model.Name, value);

                    var response = Update(rssFeed);
                    return(response.SetMessage(response.Success
                        ? T("RSSFeed_Message_UpdateRssFeedInfoSuccessfully")
                        : T("RSSFeed_Message_UpdateRssFeedInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("RSSFeed_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("RSSFeed_Message_ObjectNotFound")
            });
        }
Ejemplo n.º 3
0
        public ActionResult Create(RssFeedManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _rssFeedService.SaveRssFeed(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    var id = (int)response.Data;
                    switch (submit)
                    {
                    case SubmitType.Save:
                        return(RedirectToAction("Index"));

                    default:
                        return(RedirectToAction("Edit", new { id }));
                    }
                }
            }
            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult Edit(RssFeedManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _rssFeedService.SaveRssFeed(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));
        }