Exemplo n.º 1
0
        public ServiceResult Create(BlogsDTO model)
        {
            var entity = new Blogs();

            Mapper.Map(model, entity);

            _blogs.Add(entity);
            _Context.SaveChanges();

            return(ServiceResult.Okay());
        }
Exemplo n.º 2
0
        public IActionResult Create(BlogsDTO model, IFormFile Image)
        {
            var imageName = FileHelper.SaveFile(Image, _fileConfig, FileType.Image, _environment.WebRootPath);

            if (imageName != null)
            {
                model.Image = imageName;
            }
            var result = _blogsRepository.Create(model);

            TempData.AddResult(result);
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 保存内容
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public string SaveBlogs(BlogsDTO dto)
        {
            var entity = Mapper.Map <BlogsDTO, Blogs>(dto);

            try
            {
                blogs.Add(entity);
                return("操作成功");
            }
            catch (Exception e)
            {
                return("内部出现错误");
            }
        }
Exemplo n.º 4
0
        public async Task <BlogsDTO> GetById(int Id)
        {
            var      states = _BusinessBase.GetById(Id);
            BlogsDTO state  = new BlogsDTO();

            if (states != null)
            {
                state.Id             = states.Id;
                state.Description    = states.Description;
                state.Heading        = states.Heading;
                state.ImagesUrl      = states.ImagesUrl;
                state.OtherImagesUrl = states.OtherImagesUrl;
                state.UserName       = states.UserName;
                state.UserId         = states.UserId;
            }
            return(state);
        }
Exemplo n.º 5
0
        public async Task <IEnumerable <BlogsDTO> > Get()
        {
            var             states    = _BusinessBase.Get();
            List <BlogsDTO> stateslst = null;

            if (states != null)
            {
                stateslst = new List <BlogsDTO>();
                foreach (var item in states)
                {
                    BlogsDTO state = new BlogsDTO();
                    state.Id             = item.Id;
                    state.Description    = item.Description;
                    state.Heading        = item.Heading;
                    state.ImagesUrl      = item.ImagesUrl;
                    state.OtherImagesUrl = item.OtherImagesUrl;
                    state.UserName       = item.UserName;
                    state.UserId         = item.UserId;
                    stateslst.Add(state);
                }
            }
            return(stateslst);
        }
Exemplo n.º 6
0
        public HttpResponseMessage SaveBlogs(BlogsDTO dto)
        {
            string result = service.SaveBlogs(dto);

            return(HttpResponseExtension.toJson(result));
        }