Exemple #1
0
        public ActionResult Edit(LinkTypeManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _linkTypeService.SaveLinkType(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 }));
                    }
                }
            }
            return(View(model));
        }
Exemple #2
0
        /// <summary>
        /// Update value for property of model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateLinkTypeData(XEditableModel model)
        {
            var linkType = GetById(model.Pk);

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

                    var validationResults = manageModel.ValidateModel();

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

                    #endregion

                    linkType.SetProperty(model.Name, value);
                    var response = Update(linkType);
                    return(response.SetMessage(response.Success
                        ? T("LinkType_Message_UpdateLinkTypeInfoSuccessfully")
                        : T("LinkType_Message_UpdateLinkTypeInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("LinkType_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("LinkType_Message_ObjectNotFound")
            });
        }
Exemple #3
0
        /// <summary>
        /// Save link type
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveLinkType(LinkTypeManageModel model)
        {
            ResponseModel response;
            var           linkType = GetById(model.Id);

            if (linkType != null)
            {
                linkType.Name = model.Name;
                response      = Update(linkType);
                return(response.SetMessage(response.Success
                    ? T("LinkType_Message_UpdateSuccessfully")
                    : T("LinkType_Message_UpdateFailure")));
            }
            Mapper.CreateMap <LinkTypeManageModel, LinkType>();
            linkType = Mapper.Map <LinkTypeManageModel, LinkType>(model);
            response = Insert(linkType);
            return(response.SetMessage(response.Success
                ? T("LinkType_Message_CreateSuccessfully")
                : T("LinkType_Message_CreateFailure")));
        }
Exemple #4
0
        public ActionResult Create(LinkTypeManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _linkTypeService.SaveLinkType(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));
        }