Example #1
0
        public static object Insert(NewsVm News)
        {
            int result = 0;

            if (Utils.LoggedUser == null)
            {
                return(Utils.ServiceResponse("F036", new ModelResponse(101), null));
            }
            if (News.NewsID > 0)
            {
                if (Utils.CheckPermission(3, 27, Utils.LoggedUser.Roles) < 1)
                {
                    return(Utils.ServiceResponse("", new ModelResponse(101), null));
                }
            }
            else
            {
                if (Utils.CheckPermission(2, 27, Utils.LoggedUser.Roles) < 1)
                {
                    return(Utils.ServiceResponse("", new ModelResponse(101), null));
                }
            }


            News.PostUserID = Utils.LoggedUser.PortalUserId.ToString();
            result          = Mgr.Insert(News);
            if (result > 0)
            {
                return(new ModelResponse(0, result));
            }



            return(result);
        }
Example #2
0
        public async Task <IActionResult> Post(IFormFile files, string Text, string Title, string Course)
        {
            // full path to file in temp location
            var filePath = "/images/" + files.FileName;


            using (var fileStream = new FileStream(appEnvironment.WebRootPath + filePath, FileMode.Create))
            {
                await files.CopyToAsync(fileStream);
            }
            if (filePath == null)
            {
                filePath = " ";
            }
            var course = courseManager.Get().Where(e => e.Name == Course).FirstOrDefault();

            NewsDTO newsDTO = new NewsDTO()
            {
                Text      = Text,
                Title     = Title,
                ImagePath = filePath,
                Day       = DateTime.Today.Day,
                Month     = Enum.GetName(typeof(MonthEnum),
                                         DateTime.Today.Month - 1),
                CourseId = course.Id
            };

            newsManager.Insert(newsDTO);

            var news    = newsManager.GetAll().ToList();
            var courses = courseManager.GetAll().ToList();

            return(RedirectToAction("News"));
        }
Example #3
0
        public IActionResult PostForm(FormModelClass formModelClass)
        {
            var imageId = imageManager.Get().LastOrDefault().Id;

            News news = new News()
            {
                Text     = formModelClass.text,
                Title    = formModelClass.title,
                Image_Id = imageId,
                Day      = formModelClass.dat.Day,
                Month    = Enum.GetName(typeof(MonthEnum), formModelClass.dat.Month - 1),
                Year     = formModelClass.dat.Year
            };

            newsManager.Insert(news);
            return(RedirectToAction("News"));
        }
Example #4
0
        public IActionResult Post([FromBody] AddNews item)
        {
            var course = courseManager.Get().Where(e => e.Name == item.Course).FirstOrDefault();

            var newsDTO = new NewsDTO()
            {
                Text      = item.Text,
                Title     = item.Title,
                ImagePath = string.Empty,
                Day       = DateTime.Today.Day,
                Month     = Enum.GetName(typeof(MonthEnum),
                                         DateTime.Today.Month - 1),
                CourseId = course.Id
            };

            newsManager.Insert(newsDTO);

            var news    = newsManager.GetAll().ToList();
            var courses = courseManager.GetAll().ToList();

            return(Ok(newsDTO));
        }