Ejemplo n.º 1
0
        public async Task <IActionResult> ChangeRailwayInfo(string htmlData)
        {
            var items = await db.InfoDatas.Where(x => x.InfoType == InfoType.RAILWAY_SCHEDULE).ToListAsync();

            var item = items.LastOrDefault();

            if (item != null)
            {
                item.ChangeData = DateTime.Now;
                item.HtmlData   = htmlData;
                await db.SaveChangesAsync();
            }
            else
            {
                var newItem = new InfoData
                {
                    InfoType   = InfoType.RAILWAY_SCHEDULE,
                    ChangeData = DateTime.Now,
                    HtmlData   = htmlData
                };
                db.InfoDatas.Add(newItem);
                await db.SaveChangesAsync();
            }
            return(RedirectToAction("RailwayInfo"));
        }
        public async Task <IActionResult> SaveDocument(DocumentModel model)
        {
            //List<Image> ls = new List<Image>();
            string fileName = Guid.NewGuid() + Path.GetExtension(model.File.FileName);

            string path = Path.Combine("Files", "Documentation", fileName);

            using (var fileStream = new FileStream(Path.Combine(_environment.WebRootPath, path), FileMode.Create))
            {
                await model.File.CopyToAsync(fileStream);
            }
            //ls.Add(new Image { Name = imgName, Puth = path, IsMain = true });

            var doc = new Document
            {
                CreateDate = DateTime.Now,
                Name       = model.Name,
                Extension  = Path.GetExtension(model.File.FileName),
                Guid       = Guid.NewGuid(),
                Path       = path,
                FileType   = DocumentType.UNDEFINED
            };

            db.Documents.Add(doc);
            await db.SaveChangesAsync();

            return(RedirectToAction("DocumentList"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> SaveNews(NewsModel model)
        {
            if (model.Guid == Guid.Empty)//add save
            {
                List <Image> ls      = new List <Image>();
                string       imgName = Guid.NewGuid() + Path.GetExtension(model.MainImage.FileName);

                string path = Path.Combine("Images", "News", imgName);
                using (var fileStream = new FileStream(Path.Combine(_environment.WebRootPath, path), FileMode.Create))
                {
                    await model.MainImage.CopyToAsync(fileStream);
                }
                ls.Add(new Image {
                    Name = imgName, Puth = path, IsMain = true
                });

                var news = new News
                {
                    NewsGuid    = Guid.NewGuid(),
                    Images      = ls,
                    Title       = model.Title,
                    Content     = model.Content,
                    Description = model.Description,
                    CreateTime  = DateTime.Now
                };
                db.News.Add(news);

                await db.SaveChangesAsync();

                return(RedirectToAction("NewsDetails", new { guid = news.NewsGuid.ToString() }));
            }
            else//edit save
            {
                List <Image> ls = new List <Image>();
                if (model.MainImage != null)//main image change
                {
                    string imgName = Guid.NewGuid() + Path.GetExtension(model.MainImage.FileName);

                    string path = Path.Combine("Images", "News", imgName);
                    using (var fileStream = new FileStream(Path.Combine(_environment.WebRootPath, path), FileMode.Create))
                    {
                        await model.MainImage.CopyToAsync(fileStream);
                    }
                    ls.Add(new Image {
                        Name = imgName, Puth = path, IsMain = true
                    });
                }
                var target = await db.News.Include(x => x.Images).Where(x => x.NewsGuid == model.Guid).FirstOrDefaultAsync();

                target.Title       = model.Title;
                target.Description = model.Description;
                target.Content     = model.Content;
                if (model.MainImage != null)//main image change
                {
                    target.Images = ls;
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("NewsDetails", new { guid = target.NewsGuid.ToString() }));
            }
        }