Example #1
0
        public virtual async Task <PostAttributeModel> PreparePostAttributeModelAsync(TblPostAttributes attribute)
        {
            PostAttributeModel result;

            if (attribute == null)
            {
                result = new PostAttributeModel();
            }
            else
            {
                result = attribute.Adapt <PostAttributeModel>();
                await attribute.LoadAllLocalizedStringsToModelAsync(result);
            }

            return(result);
        }
        public virtual async Task <ActionResult> Editor(PostAttributeModel model, bool?saveAndContinue)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var record   = _postAttributesModelFactory.PrepareTblPostAttributes(model);
            var recordId = model.Id;

            try
            {
                if (model.Id == null)
                {
                    //Add new record
                    recordId = await _postAttributesService.AddAsync(record);
                }
                else
                {
                    //Edit record
                    await _postAttributesService.UpdateAsync(record);
                }

                await _localizedEntityService.SaveAllLocalizedStringsAsync(record, model);
            }
            catch (Exception e)
            {
                var errorCode = ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Error(e, System.Web.HttpContext.Current));
                ModelState.AddModelError("", string.Format(_localizationService.GetResource("ErrorOnOperation"), e.Message, errorCode));
                return(View(model));
            }

            if (saveAndContinue != null && saveAndContinue.Value)
            {
                return(RedirectToAction("Editor", "ManagePostAttributes", new { id = recordId }));
            }

            return(Content(@"<script language='javascript' type='text/javascript'>
                                window.close();
                                window.opener.refreshPostAttributesGrid();
                             </script>"));
        }
Example #3
0
        public virtual TblPostAttributes PrepareTblPostAttributes(PostAttributeModel attribute)
        {
            var result = attribute.Adapt <TblPostAttributes>();

            return(result);
        }