コード例 #1
0
        public IActionResult Edit(int id)
        {
            PageNewsType              PageNewsType = _PageNewsTypeRepository.Get(id);
            NewsTypeViewModel         NewsTypeVm   = PageNewsType.MapToPageNewsTypeViewModelInEdit();
            PageNewsTypeEditViewModel viewModel    = new PageNewsTypeEditViewModel(NewsTypeVm);

            return(View(viewModel));
        }
コード例 #2
0
        public JsonResult EditNewsType(NewsTypeViewModel newsTypeViewModel)
        {
            try
            {
                var token = _tokenValidator.Validate(HttpContext);
                if (!token.Success)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        NotAuthenticated = true,
                        Message = $"Unauthorized:-{token.Message}",
                    }));
                }
                if (token.Role != Role.Admin)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        NotAuthenticated = true,
                        Message = "Sorry, you are not authorized to access this page",
                    }));
                }
                var newType = _context.PortalNewsTypes.FirstOrDefault(t => t.Id == newsTypeViewModel.Id);
                if (newType == null)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        Message = "Could not find news type"
                    }));
                }

                newType.NewsTypeName = newsTypeViewModel.NewsTypeName;
                newType.Status       = newsTypeViewModel.Status;

                _context.Update(newType);
                _context.SaveChanges();

                return(Json(new ReturnData <string>
                {
                    Success = true,
                    Message = "Successful"
                }));
            }
            catch (Exception ex)
            {
                return(Json(new ReturnData <string>
                {
                    Success = false,
                    Message = "Server Error, Please try again",
                    Error = new Error(ex)
                }));
            }
        }
コード例 #3
0
        //edit get
        public static NewsTypeViewModel MapToPageNewsTypeViewModelInEdit(this PageNewsType PageNewsType)
        {
            NewsTypeViewModel newsTypeViewModel = new NewsTypeViewModel
            {
                Id     = PageNewsType.Id,
                EnName = PageNewsType.EnName,
                ArName = PageNewsType.ArName,
            };

            return(newsTypeViewModel);
        }
コード例 #4
0
        public IActionResult Edit(NewsTypeViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = _dbContext.NewsType.FirstOrDefault(x => x.NewsTypeUuid.ToString() == model.NewsTypeUuid);
                entity.NewsTypeName = model.NewsTypeName;
                entity.Remark       = model.Remark;
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("编辑", "成功:编辑:新闻类型列表信息一条数据", _dbContext);
                }
                response = ResponseModelFactory.CreateInstance;
                return(Ok(response));
            }
        }
コード例 #5
0
        public IActionResult Create(NewsTypeViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = new NewsType();
                entity.NewsTypeName = model.NewsTypeName;
                entity.NewsTypeUuid = Guid.NewGuid();
                entity.Remark       = model.Remark;
                entity.IsDeleted    = 0;
                entity.AddPeople    = AuthContextService.CurrentUser.LoginName;
                entity.AddTime      = DateTime.Now.ToString("yyyy-MM-dd");
                _dbContext.NewsType.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:新闻类型列表信息一条数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }
コード例 #6
0
        public JsonResult AddNewsTypes(NewsTypeViewModel newsTypeViewModel)
        {
            try
            {
                var token = _tokenValidator.Validate(HttpContext);
                if (!token.Success)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        NotAuthenticated = true,
                        Message = $"Unauthorized:-{token.Message}",
                    }));
                }
                if (token.Role != Role.Admin)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        NotAuthenticated = true,
                        Message = "Sorry, you are not authorized to perform this action",
                    }));
                }
                if (!string.IsNullOrEmpty(newsTypeViewModel.NewsTypeName))
                {
                    var newsType = new PortalNewsType
                    {
                        NewsTypeName = newsTypeViewModel.NewsTypeName,
                        Status       = newsTypeViewModel.Status
                    };

                    if (newsTypeViewModel.Id.HasValue && newsTypeViewModel.Id.Value > 0)
                    {
                        newsType.Id = newsType.Id;
                        _context.PortalNewsTypes.Update(newsType);
                    }
                    else
                    {
                        _context.PortalNewsTypes.Add(newsType);
                    }

                    _context.SaveChanges();

                    return(Json(new ReturnData <string>
                    {
                        Success = true,
                        Message = "Successful"
                    }));
                }

                return(Json(new ReturnData <string>
                {
                    Success = false,
                    Message = "News type name can not be empty"
                }));
            }
            catch (Exception ex)
            {
                return(Json(new ReturnData <string>
                {
                    Success = false,
                    Message = "An error occurred,please retry : " + ex.Message
                }));
            }
        }