Beispiel #1
0
        /// <summary>
        /// Update value for property of model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateServiceData(XEditableModel model)
        {
            var service = GetById(model.Pk);

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

                    var validationResults = manageModel.ValidateModel();

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

                    #endregion

                    service.SetProperty(model.Name, value);
                    var response = Update(service);
                    return(response.SetMessage(response.Success
                        ? T("Service_Message_UpdateServiceInfoSuccessfully")
                        : T("Service_Message_UpdateServiceInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("Service_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("Service_Message_ObjectNotFound")
            });
        }
Beispiel #2
0
        public ActionResult Edit(ServiceManageModel model, SubmitTypeEnums submit)
        {
            if (ModelState.IsValid)
            {
                var response = _serviceServices.SaveServiceManageModel(model);
                if (response.Success)
                {
                    SetSuccessMessage(response.Message);
                    switch (submit)
                    {
                    case SubmitTypeEnums.Save:
                        return(RedirectToAction("Index"));

                    default:
                        return(RedirectToAction("Edit", new { id = model.Id }));
                    }
                }
                SetErrorMessage(response.Message);
            }
            model.StatusList = _serviceServices.GetStatus();
            return(View(model));
        }
Beispiel #3
0
        public ActionResult Create(ServiceManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _serviceService.SaveServiceManageModel(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 }));
                    }
                }
            }
            model.StatusList = _serviceService.GetStatus();
            return(View(model));
        }
Beispiel #4
0
        /// <summary>
        /// Save Service manage model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveServiceManageModel(ServiceManageModel model)
        {
            ResponseModel response;
            var           service = GetById(model.Id);

            #region Edit Service

            if (service != null)
            {
                service.Name = model.Name;

                service.Status      = model.Status;
                service.Description = model.Description;
                service.Content     = model.Content;
                service.ImageUrl    = model.ImageUrl;

                //Get page record order
                response = Update(service);
                return(response.SetMessage(response.Success
                    ? T("Service_Message_UpdateSuccessfully")
                    : T("Service_Message_UpdateFailure")));
            }

            #endregion

            service = new Service
            {
                Name        = model.Name,
                Status      = model.Status,
                Description = model.Description,
                Content     = model.Content,
                ImageUrl    = model.ImageUrl
            };
            response = Insert(service);
            return(response.SetMessage(response.Success
                ? T("Service_Message_CreateSuccessfully")
                : T("Service_Message_CreateFailure")));
        }
Beispiel #5
0
        /// <summary>
        /// Save Service manage model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveServiceManageModel(ServiceManageModel model)
        {
            ResponseModel response;
            var           service = GetById(model.Id);

            #region Edit Service
            if (service != null)
            {
                service.Title = model.Title;

                service.Status      = model.Status;
                service.Description = model.Description;
                service.Content     = model.Content;
                service.ImageUrl    = model.ImageUrl;

                //Get page record order
                response = Update(service);
                return(response.SetMessage(response.Success ?
                                           _localizedResourceServices.T("AdminModule:::Services:::Messages:::UpdateSuccessfully:::Update service successfully.")
                    : _localizedResourceServices.T("AdminModule:::Services:::Messages:::UpdateFailure:::Update service failed. Please try again later.")));
            }
            #endregion

            service = new Service
            {
                Title       = model.Title,
                Status      = model.Status,
                Description = model.Description,
                Content     = model.Content,
                ImageUrl    = model.ImageUrl
            };
            response = Insert(service);
            return(response.SetMessage(response.Success ?
                                       _localizedResourceServices.T("AdminModule:::Services:::Messages:::CreateSuccessfully:::Create service successfully.")
                : _localizedResourceServices.T("AdminModule:::Services:::Messages:::CreateFailure:::Create service failed. Please try again later.")));
        }
Beispiel #6
0
        public ActionResult Edit(ServiceManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _serviceService.SaveServiceManageModel(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));
        }