示例#1
0
        public ActionResult PopupEdit(AssociateTypeManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _associateTypeService.SaveAssociateType(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    switch (submit)
                    {
                    case SubmitType.PopupSave:
                        return(View("CloseFancyBox", new CloseFancyBoxViewModel
                        {
                            IsReload = false,
                            ReturnUrl = string.Empty
                        }));

                    case SubmitType.SaveAndContinueEdit:
                        return(RedirectToAction("PopupEdit", new { id = model.Id }));
                    }
                }
            }
            SetupPopupAction();
            return(View(model));
        }
        /// <summary>
        /// Update value for property of model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateAssociateTypeData(XEditableModel model)
        {
            var associateType = GetById(model.Pk);

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

                    #region Validate

                    var manageModel = new AssociateTypeManageModel(associateType);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

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

                    #endregion

                    associateType.SetProperty(model.Name, value);
                    var response = Update(associateType);

                    return(response.SetMessage(response.Success
                        ? T("AssociateType_Message_UpdateAssociateTypeInfoSuccessfully")
                        : T("AssociateType_Message_UpdateAssociateTypeInfoFailure")));
                }

                return(new ResponseModel
                {
                    Success = false,
                    Message = T("AssociateType_Message_PropertyNotFound")
                });
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("AssociateType_Message_ObjectNotFound")
            });
        }
示例#3
0
        public ActionResult Create(AssociateTypeManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _associateTypeService.SaveAssociateType(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));
        }
示例#4
0
        public ActionResult Edit(AssociateTypeManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _associateTypeService.SaveAssociateType(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));
        }
        /// <summary>
        /// Save associate type
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveAssociateType(AssociateTypeManageModel model)
        {
            ResponseModel response;
            var           associateType = GetById(model.Id);

            if (associateType != null)
            {
                associateType.Name        = model.Name;
                associateType.RecordOrder = model.RecordOrder;
                response = Update(associateType);

                return(response.SetMessage(response.Success
                    ? T("AssociateType_Message_UpdateSuccessfully")
                    : T("AssociateType_Message_UpdateFailure")));
            }
            Mapper.CreateMap <AssociateTypeManageModel, AssociateType>();
            associateType = Mapper.Map <AssociateTypeManageModel, AssociateType>(model);

            response = Insert(associateType);

            return(response.SetMessage(response.Success
                ? T("AssociateType_Message_CreateSuccessfully")
                : T("AssociateType_Message_CreateFailure")));
        }