Example #1
0
        public ActionResult del_set_check(BoardList doc, int file_idx)
        {
            BoardList _updateContent =
                (from a in db.BoardList where a.idx == doc.idx select a).Single();

            _updateContent.title    = doc.title;
            _updateContent.content  = doc.content;
            _updateContent.editDate = DateTime.Now;

            db.SaveChanges(); // 실제로 저장

            #region 삭제


            BoardFile _update =
                (from a in db.BoardFile where a.id == file_idx select a).Single();
            _update.use_yn = "N";


            db.SaveChanges(); // 실제로 저장

            #endregion


            return(Redirect("/board/BoardWrite?cate=" + doc.BM_idx + "&idx=" + doc.idx));
        }
Example #2
0
        // Corresponds to "File/Open"
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog();

            openFileDialog.AddExtension    = true;
            openFileDialog.CheckFileExists = true;
            openFileDialog.DefaultExt      = "frb";
            openFileDialog.Filter          = "Fortune Street Board (.frb) | *.frb";
            openFileDialog.Multiselect     = false;
            if (openFileDialog.ShowDialog() != true)
            {
                return;
            }

            currentFileName = openFileDialog.FileName;
            loneFileName    = openFileDialog.SafeFileName;

            using (var stream = openFileDialog.OpenFile())
            {
                MiscUtil.IO.EndianBinaryReader binReader = new MiscUtil.IO.EndianBinaryReader(MiscUtil.Conversion.EndianBitConverter.Big, stream);
                var Board = BoardFile.LoadFromStream(binReader);
                this.DataContext = Board;
            }
            UpdateTitle();
        }
Example #3
0
        public void populate(BoardFile file)
        {
            Mosaic.maxMosaicSize     = file.maxMosaicSize;
            Mosaic.minMosaicSize     = Mosaic.maxMosaicSize - 6;
            GridProp.GridSize        = Mosaic.maxMosaicSize;
            GridProp.MinMosaicSize   = Mosaic.minMosaicSize;
            GridProp.GridWidthCount  = file.width;
            GridProp.GridHeightCount = file.height;
            GridProp.GridWidth       = GridProp.GridWidthCount * GridProp.GridSize;
            GridProp.GridHeight      = GridProp.GridHeightCount * GridProp.GridSize;
            GridProp.BackgroundColor = backgroundColors.Find(x => x.ColorName == file.backgroundColor.ColorName);
            GridProp.Light           = file.light;

            selectedMosaic.Size = Mosaic.maxMosaicSize;


            mosaicGrid.Children.Clear();
            listMosaic.Clear();
            for (int i = 0; i < file.mosaicGrid.Count; i++)
            {
                Grid grid = new Grid();
                grid.Width  = GridProp.GridSize;
                grid.Height = GridProp.GridSize;
                ContentControl contentControl = new ContentControl();
                contentControl.ContentTemplate = mosaicTemplate;
                Binding myBinding = new Binding("Mosaic");
                listMosaic.Add(file.mosaicGrid[i]);
                myBinding.Source = listMosaic.Last();
                myBinding.Path   = new PropertyPath("Mosaic");
                contentControl.SetBinding(ContentControl.ContentProperty, myBinding);
                grid.Children.Add(contentControl);
                mosaicGrid.Children.Add(grid);
            }
        }
Example #4
0
        public async Task <IHttpActionResult> PutBoardFile(int id, BoardFile BoardFile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != BoardFile.BoardFileNo)
            {
                return(BadRequest());
            }

            db.Entry(BoardFile).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BoardFileExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #5
0
        public ActionResult Photo_Del(int?idx, string cate)
        {
            if (idx == null)
            {
                return(HttpNotFound());
            }
            string    msg   = "";
            BoardFile board = db.BoardFile.Find(idx);

            #region 권한체크

            string user = User.Identity.Name;
            int    auth = 0;
            try
            {
                auth = Convert.ToInt16(Request.Cookies["check_auth"].Value);
            }
            catch
            {
            }

            string ok_auth = "N";

            DateTime _today = DateTime.Today;
            DateTime _wdate = board.Board.BD_wdate;

            TimeSpan ts   = _today - _wdate;
            int      days = Convert.ToInt32(ts.TotalDays);

            if (board.Board.BD_writer == user && days <= 5)
            {
                ok_auth = "Y";
            }
            if (auth >= 8)
            {
                ok_auth = "Y";
            }



            #endregion

            if (ok_auth == "Y")
            {
                board.BF_useable = 0;
                db.SaveChanges();
                msg = Util.msg.msg_del;
            }
            else
            {
                msg = Util.msg.msg_no;
            }


            string BM_url = "/board/photo_list?cate=" + cate;

            return(Content("<script>alert('" + msg + "'); location.href='" + BM_url + "';</script>"));
        }
Example #6
0
        // Corresponds to "File/New"
        private void New_Click(object sender, RoutedEventArgs e)
        {
            currentFileName = null;
            loneFileName    = null;
            var Board = BoardFile.LoadDefault();

            this.DataContext = Board;
            UpdateTitle();
        }
Example #7
0
        public ActionResult UpdateBoard(supertalentoftheworld.Models.Board board)
        {
            int cate = board.BD_BM_idx;
            //기존 파일 변동사항을 파악한다
            string oriFileIdxs = Request["oriFileIdx"];

            List <int> oriFileIdxList = oriFileIdxs != null?oriFileIdxs.Split(',').Select(Int32.Parse).ToList() : null;

            supertalentoftheworld.Models.Board oriBoard = db.Board.Find(board.BD_idx);

            //DB에 원래 있던 파일들
            IEnumerable <BoardFile> dbfiles = oriBoard.BoardFile.Where(a => a.BF_useable == 1);

            foreach (BoardFile dbfile in dbfiles)
            {
                //변경된 파일에도 포함되어 있으면 그대로 유지, 아니면 useable = 0으로 변경
                if (!oriFileIdxList.Contains(dbfile.BF_idx))
                {
                    dbfile.BF_useable = 0;
                }
            }

            // 새로 들어온 파일들 체크
            var           fm    = new FileManager();
            List <string> files = fm.FileUpload();

            foreach (string file in files)
            {
                var bf = new BoardFile();
                bf.BF_BD_idx  = board.BD_idx;
                bf.BF_name    = file;
                bf.BF_useable = 1;
                bf.BF_wdate   = DateTime.Now;

                db.BoardFile.Add(bf);
            }

            //게시판 내용들 업데이트
            board.BD_edate = DateTime.Now;

            supertalentoftheworld.Models.Board updateboard = db.Board.Find(board.BD_idx);

            updateboard.BD_BM_idx   = board.BD_BM_idx;
            updateboard.BD_title    = board.BD_title;
            updateboard.BD_writer   = User.Identity.Name;
            updateboard.BD_password = board.BD_password;
            updateboard.BD_content  = board.BD_content;
            updateboard.BD_edate    = DateTime.Now;


            db.SaveChanges();


            string returnUrl = "/board/board_list?cate=" + cate;

            return(Redirect(returnUrl));
        }
Example #8
0
        public async Task <IHttpActionResult> GetBoardFile(int id)
        {
            BoardFile BoardFile = await db.BoardFiles.FindAsync(id);

            if (BoardFile == null)
            {
                return(NotFound());
            }

            return(Ok(BoardFile));
        }
Example #9
0
        public static void saveFile(BoardFile file, String path)
        {
            BinaryFormatter bf = new BinaryFormatter();

            FileStream fsout = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);

            using (fsout)
            {
                bf.Serialize(fsout, file);
            }
        }
Example #10
0
        public async Task <IHttpActionResult> PostBoardFile(BoardFile BoardFile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.BoardFiles.Add(BoardFile);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = BoardFile.BoardFileNo }, BoardFile));
        }
Example #11
0
        public static BoardFile loadFile(string filename)
        {
            BoardFile board = new BoardFile();

            BinaryFormatter bf = new BinaryFormatter();

            FileStream fsin = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);

            using (fsin)
            {
                board = (BoardFile)bf.Deserialize(fsin);
            }
            return(board);
        }
Example #12
0
        public async Task <IHttpActionResult> DeleteBoardFile(int id)
        {
            BoardFile BoardFile = await db.BoardFiles.FindAsync(id);

            if (BoardFile == null)
            {
                return(NotFound());
            }

            db.BoardFiles.Remove(BoardFile);
            await db.SaveChangesAsync();

            return(Ok(BoardFile));
        }
        public void TryParse_Valid_QueenToPosition(string message, BoardFile toFile, BoardRank toRank)
        {
            var target = new MovePromotionParser();
            var parsed = target.TryParse(message, out var promotion);

            Assert.IsTrue(parsed);

            Assert.IsNull(promotion.FromFile);
            Assert.IsNull(promotion.FromRank);
            Assert.IsFalse(promotion.Captures);

            Assert.AreEqual(toFile, promotion.ToFile);
            Assert.AreEqual(toRank, promotion.ToRank);

            Assert.AreEqual(Piece.Queen, promotion.PromotionToPiece);

            Assert.IsFalse(promotion.Check);
            Assert.IsFalse(promotion.Checkmate);
        }
        public void TryParse_Valid_ToPosition(string message, BoardFile toFile, BoardRank toRank)
        {
            var target = new MovePieceParser();
            var parsed = target.TryParse(message, out var pieceDto);

            Assert.IsTrue(parsed);

            Assert.AreEqual(Piece.Empty, pieceDto.Piece);

            Assert.IsNull(pieceDto.FromFile);
            Assert.IsNull(pieceDto.FromRank);
            Assert.IsFalse(pieceDto.Captures);

            Assert.AreEqual(toFile, pieceDto.ToFile);
            Assert.AreEqual(toRank, pieceDto.ToRank);

            Assert.IsFalse(pieceDto.Check);
            Assert.IsFalse(pieceDto.Checkmate);
        }
Example #15
0
        public ActionResult CreateBoard(supertalentoftheworld.Models.Board board)
        {
            int cate = board.BD_BM_idx;



            if (ModelState.IsValid)
            {
                board.BD_wdate   = DateTime.Now;
                board.BD_hit     = 0;
                board.BD_useable = 1;
                board.BD_writer  = User.Identity.Name;

                db.Board.Add(board);
            }

            var           fm    = new FileManager();
            List <string> files = fm.FileUpload();

            int BD_idx = db.Board.Any() ? db.Board.Max(a => a.BD_idx) + 1 : 1;

            foreach (string file in files)
            {
                var bf = new BoardFile();
                bf.BF_BD_idx  = BD_idx;
                bf.BF_name    = file;
                bf.BF_useable = 1;
                bf.BF_wdate   = DateTime.Now;


                db.BoardFile.Add(bf);
            }
            db.SaveChanges();


            string returnUrl = "/board/board_list?cate=" + cate;

            return(Redirect(returnUrl));


            //return Content("<script>location.href='"+ returnUrl + "';</script>");
        }
Example #16
0
        void SaveFile(object parameter)
        {
            BoardFile newFile = new BoardFile();

            newFile.backgroundColor = GridProp.BackgroundColor;
            newFile.height          = GridProp.GridHeightCount;
            newFile.width           = GridProp.GridWidthCount;
            newFile.maxMosaicSize   = GridProp.GridSize;
            newFile.mosaicGrid      = listMosaic;
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.DefaultExt       = ".binary";
            dlg.Filter           = "Binary Files|*.binary";
            dlg.InitialDirectory = System.IO.Path.GetFullPath(Directory.GetCurrentDirectory());
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                FileUtils.saveFile(newFile, dlg.FileName);
            }
        }
Example #17
0
        public async Task <IActionResult> Board_action(BoardList doc, int?idx, int cate, string mode_type, List <IFormFile> files)
        {
            string file_id = "";
            string user_id = User.Identity.Name;
            string msg     = "";

            if (idx == null)
            {
                msg     = "입력";
                file_id = DateTime.Now.ToShortDateString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();

                #region 저장
                doc.fileId    = file_id;
                doc.useable   = "Y";
                doc.writeDate = DateTime.Now;
                doc.editDate  = DateTime.Now;
                db.BoardList.Add(doc);
                db.SaveChanges(); // 실제로 저장


                #endregion
            }
            else
            {
                int _idx = Convert.ToInt32(idx);

                if (mode_type == "D")
                {
                    #region 삭제

                    msg = "삭제";
                    BoardList _update =
                        (from a in db.BoardList where a.idx == idx select a).Single();

                    _update.useable = "N";
                    _update.delDate = DateTime.Now;

                    db.SaveChanges(); // 실제로 저장

                    #endregion
                }
                else
                {
                    #region 수정
                    msg = "수정";
                    #region  일 아이디
                    file_id = doc.fileId;

                    if (string.IsNullOrEmpty(file_id))
                    {
                        file_id = user_id + DateTime.Now.ToShortDateString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();

                        doc.fileId = file_id;
                    }
                    #endregion


                    doc.editDate        = DateTime.Now;
                    doc.writeDate       = DateTime.Now;
                    db.Entry(doc).State = EntityState.Modified;

                    //idx 제외 업데이트=================================
                    db.Entry(doc).Property("idx").IsModified = false;
                    //==================================================
                    db.SaveChanges();



                    #endregion
                }
            }

            #region  일 올리기


            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
            Configuration = builder.Build();
            string Models_photo = Configuration["user_app:file_list_url"];
            string company_id   = UserData.user_get(user_id, "company_id");


            int s = 1;
            foreach (var formFile in files)
            {
                double file_size = formFile.Length;
                if (file_size < _fileSizeLimit)
                {
                    var formFileContent =
                        await FileHelpers
                        .ProcessFormFile <IFormFile>(
                            formFile, ModelState, _permittedExtensions,
                            _fileSizeLimit);



                    #region 변수
                    // 변수 =========================================================================================================================
                    string only = user_id + DateTime.Today.ToShortDateString().Replace("-", "") + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
                    //  var trustedFileNameForFileStorage = Path.GetRandomFileName();   //랜덤이름

                    string file_ex = ""; // 확장자

                    try { file_ex = Path.GetFileName(formFile.FileName).Split('.').Last(); }
                    catch
                    {
                    }
                    var _fileName = only + "." + file_ex;     // 신규 파일 이름



                    var    _local_path      = _targetFilePath + company_id + "/";   // 신규 파일 경로
                    var    filePath         = Path.Combine(_local_path, _fileName); // 전체 경로
                    string desiredThumbPath = _local_path + "s/";                   // 작은 이미지 전체 경로

                    string ore_fileName = Path.GetFileName(formFile.FileName);
                    #endregion



                    //경로에 폴더가 없으면 만들어준다.=============================================
                    var dInfo   = new DirectoryInfo(_local_path);
                    var dInfo_s = new DirectoryInfo(desiredThumbPath);
                    if (!dInfo.Exists)
                    {
                        dInfo.Create();
                    }
                    if (!dInfo_s.Exists)
                    {
                        dInfo_s.Create();
                    }
                    //=================================================================================



                    using (var fileStream = System.IO.File.Create(filePath))
                    {
                        await fileStream.WriteAsync(formFileContent);
                    }

                    if (get_word.img_check(file_ex) == "img")
                    {
                        // 세로 기준
                        ResizeImage(desiredThumbPath, formFile, _fileName, 300, 0);
                    }



                    var _insert = new BoardFile()
                    {
                        Md_id      = file_id,
                        ImagePath  = Models_photo + company_id + "/" + _fileName,
                        fileName   = ore_fileName,
                        use_yn     = "Y",
                        file_ex    = file_ex,
                        file_size  = file_size,
                        r_date     = DateTime.Now,
                        write_id   = user_id,
                        sImagePath = Models_photo + company_id + "/s/" + _fileName,
                    };

                    db.BoardFile.Add(_insert);
                    db.SaveChanges();
                }

                s++;
            }


            #endregion

            //===============================================================================
            UserData history = new UserData();
            history.History_write(User.Identity.Name, "/board/boardwrite/cate=" + cate, msg);
            //==============================================================================

            string returnUrl = "/board/board_list?cate=" + cate;

            return(Redirect(returnUrl));
        }
Example #18
0
        public MainViewModel(WrapPanel mosaicGrid, DataTemplate template)
        {
            MainViewModel.usedColors = new List <MosaicColors>();
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.DarkRed, "Dark Red"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.Red, "Red"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.Pink, "Pink"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.OrangeRed, "Dark Orange"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.Orange, "Orange"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.Yellow, "Yellow"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.SeaGreen, "Dark Green"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.LimeGreen, "Green"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.LawnGreen, "Light Green"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.Navy, "Dark Blue"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.RoyalBlue, "Blue"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.DeepSkyBlue, "Light Blue"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.BlueViolet, "Violet"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.Purple, "Purple"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.Black, "Black"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.White, "White"));
            MainViewModel.usedColors.Add(new MosaicColors(Brushes.Transparent, "None"));

            backgroundColors = new List <MosaicColors>();
            backgroundColors.Add(new MosaicColors(Brushes.Black, "Black", Brushes.White));
            backgroundColors.Add(new MosaicColors(Brushes.Maroon, "Dark Red", Brushes.White));
            backgroundColors.Add(new MosaicColors(Brushes.DarkGreen, "Dark Green", Brushes.White));
            backgroundColors.Add(new MosaicColors(Brushes.MidnightBlue, "Dark Blue", Brushes.White));
            backgroundColors.Add(new MosaicColors(Brushes.White, "White", Brushes.Black));
            backgroundColors.Add(new MosaicColors(Brushes.LightSalmon, "Light Red", Brushes.Black));
            backgroundColors.Add(new MosaicColors(Brushes.YellowGreen, "Light Green", Brushes.Black));
            backgroundColors.Add(new MosaicColors(Brushes.PowderBlue, "Light Blue", Brushes.Black));

            gridSettingMove = false;
            gridSettingCopy = false;
            gridSettingSwap = true;
            GridProp        = new GridProperties();
            this.mosaicGrid = mosaicGrid;
            mosaicTemplate  = template;
            listMosaic      = new List <MosaicWrapper>();


            Colors = new List <MosaicColors>();
            foreach (MosaicColors color in usedColors)
            {
                Colors.Add(new MosaicColors(color.Color, color.ColorName));
            }
            selectedMosaic                 = new Mosaic(int.MaxValue);
            selectedMosaic.Color.Color     = Brushes.Red.ToString();
            selectedMosaic.Color.ColorName = "Red";
            selectedMosaic.IsCircle        = true;
            selectedMosaic.IsPolygon       = false;

            BoardFile newFile = new BoardFile();

            populate(newFile);

            OpenFileCommand = new RelayCommand(OpenFile);
            SaveFileCommand = new RelayCommand(SaveFile);
            CloseAppCommand = new RelayCommand(CloseApp);

            NewGridCommand       = new RelayCommand(NewBoard);
            NewRandomGridCommand = new RelayCommand(generateNewRandomBoard);

            ShowHelpCommand  = new RelayCommand(ShowHelpWindow);
            ShowAboutCommand = new RelayCommand(ShowAboutWindow);
        }
Example #19
0
        public ActionResult m_photo_list(int?cate, int?page)
        {
            string web_company_id    = Request.Cookies["web_company_id"].Value ?? "";
            string web_department_id = Request.Cookies["web_department_id"].Value ?? "";
            int    auth        = Convert.ToInt16(Request.Cookies["check_auth"].Value);
            string search_type = Request["search_type"] ?? "";

            string LoadFileUrl = ConfigurationManager.AppSettings["LoadFileUrl"];

            ViewBag.LoadFileUrl = LoadFileUrl;

            string machine_id_search = search_type;

            cate = 7;

            //int _cate = 0;

            //if (cate == null)
            //{
            //    _cate =
            //        (from a in db.BoardMenu
            //         where (a.department_id == web_department_id || a.open_yn == "Y")
            //         select a.BM_idx).FirstOrDefault();
            //    cate = _cate;
            //}

            //if (!string.IsNullOrEmpty(search_type))
            //{
            //    cate = Convert.ToInt32(search_type);

            //}
            string search_text = Request["search_text"] ?? "";
            string cate_str    = cate.ToString();

            ViewBag.search_all  = search_text;
            ViewBag.search_type = machine_id_search;
            //var data = db.BoardMenu.Find(id);

            //========================================================================================================================================================
            var Code_machine_parts =
                db.project_main.Where(p => p.mode_type == "Y" && p.use_yn != "D").OrderBy(o => o.project_name).Select(
                    c => new { 값 = c.project_id, 이름 = c.project_name });

            ViewBag.세팅 = new SelectList(Code_machine_parts.AsEnumerable(), "값", "이름");
            //========================================================================================================================================================



            BoardMenu bm = db.BoardMenu.Find(cate);

            ViewBag.BoardMenu = bm;

            string _type = (from a in db.BoardMenu where a.BM_idx == cate select a.BM_type).FirstOrDefault() ?? "photo";


            ViewBag.타입 = _type;


            var board = new BoardFile();


            if (auth >= 8)
            {
                //회사별 데이터 드롭다운==============================================================================================================================================
                var category =
                    db.BoardMenu.Where(
                        a =>
                        a.BM_com == web_company_id && a.BM_type == "photo" &&
                        ((a.department_id == web_department_id || a.open_yn == "Y"))).Select(
                        a => new { a.BM_idx, a.BM_title });
                ViewBag.category = new SelectList(category.AsEnumerable(), "BM_idx", "BM_title", board.BD_BM_idx);
                //=====================================================================================================================================================================
            }
            else
            {
                //회사별 데이터 드롭다운==============================================================================================================================================
                var category =
                    db.BoardMenu.Where(
                        a =>
                        a.BM_com == web_company_id && a.BM_type == "photo" &&
                        ((a.department_id == web_department_id || a.open_yn == "Y"))).Select(
                        a => new { a.BM_idx, a.BM_title });
                ViewBag.category = new SelectList(category.AsEnumerable(), "BM_idx", "BM_title", board.BD_BM_idx);
                //=====================================================================================================================================================================
            }


            if (bm == null)
            {
                var emptyboard = new List <BoardFile>();


                board.Board.BD_BM_idx = 0;
                board.Board.BD_title  = "게시글이 없습니다.";
                board.Board.BD_writer = "마스터";
                board.Board.BD_wdate  = DateTime.Now;
                board.BoardMenu       = bm;
                board.BD_BM_idx       = 0;
                emptyboard.Add(board);
                return(View(emptyboard));
            }
            else
            {
                #region 포토

                IQueryable <BoardFile> data =
                    (from a in db.BoardFile where a.BD_BM_idx == cate && a.BF_useable == 1 && a.BF_type == "P" select a);

                if (!string.IsNullOrEmpty(machine_id_search))
                {
                    data = data.Where(p => p.machine_id == machine_id_search);
                }

                if (!string.IsNullOrEmpty(search_text))
                {
                    data = data.Where(p => p.Board.BD_title.StartsWith(search_text) || p.Board.BD_writer == search_text);
                }



                //페이징 처리
                var pg = new pagination();

                pg.totalcount     = data.Any() ? data.Count() : 1;
                pg.takecount      = 30;
                pg.skipcount      = page == null ? 0 : (int)page * pg.takecount;
                pg.totalpagecount = Math.Ceiling((double)pg.totalcount / pg.takecount);
                data = data.OrderByDescending(a => a.BF_wdate).Skip(pg.skipcount).Take(pg.takecount);

                ViewBag.pagination = pg;
                ViewBag.cate       = cate.ToString();

                List <BoardFile> boarddata = data.ToList();

                return(View(boarddata));

                #endregion
            }
        }
        public async Task <IHttpActionResult> PostBoard()
        {
            PetterResultType <Board> petterResultType = new PetterResultType <Board>();
            List <Board>             list             = new List <Board>();
            List <BoardFile>         boardFiles       = new List <BoardFile>();

            Board board = new Board();

            if (Request.Content.IsMimeMultipartContent())
            {
                string folder = HostingEnvironment.MapPath(UploadPath.BoardPath);
                Utilities.CreateDirectory(folder);

                var provider = await Request.Content.ReadAsMultipartAsync();

                foreach (var content in provider.Contents)
                {
                    string fieldName = content.Headers.ContentDisposition.Name.Trim('"');
                    if (!string.IsNullOrEmpty(content.Headers.ContentDisposition.FileName))
                    {
                        BoardFile boardFile = new BoardFile();
                        var       file      = await content.ReadAsByteArrayAsync();

                        string oldFileName = HttpUtility.UrlDecode(content.Headers.ContentDisposition.FileName.Trim('"'));
                        string fileName    = Utilities.additionFileName(oldFileName);

                        if (!FileExtension.BoardExtensions.Any(x => x.Equals(Path.GetExtension(fileName.ToLower()), StringComparison.OrdinalIgnoreCase)))
                        {
                            petterResultType.IsSuccessful = false;
                            petterResultType.JsonDataSet  = null;
                            petterResultType.ErrorMessage = ResultErrorMessage.FileTypeError;
                            return(Ok(petterResultType));
                        }

                        string fullPath = Path.Combine(folder, fileName);
                        File.WriteAllBytes(fullPath, file);
                        string thumbnamil = Path.GetFileNameWithoutExtension(fileName) + "_thumbnail" + Path.GetExtension(fileName);

                        Utilities.ResizeImage(fullPath, thumbnamil, FileSize.BoardWidth, FileSize.BoardHeight, ImageFormat.Png);

                        // 소식 대표 이미지
                        if (fieldName == FieldName.BoardFieldName)
                        {
                            board.FileName = fileName;
                            board.FilePath = UploadPath.BoardPath.Replace("~", "");
                        }

                        boardFile.FileName     = fileName;
                        boardFile.FilePath     = UploadPath.BoardPath.Replace("~", "");
                        boardFile.DateCreated  = DateTime.Now;
                        boardFile.DateModified = DateTime.Now;
                        boardFile.StateFlag    = StateFlags.Use;

                        boardFiles.Add(boardFile);
                    }
                    else
                    {
                        string str = await content.ReadAsStringAsync();

                        string item = HttpUtility.UrlDecode(str);

                        #region switch case
                        switch (fieldName)
                        {
                        case "StoreNo":
                            board.StoreNo = int.Parse(item);
                            break;

                        case "CodeID":
                            board.CodeID = item;
                            break;

                        case "MemberID":
                            board.MemberID = item;
                            break;

                        case "Title":
                            board.Title = item;
                            break;

                        case "Content":
                            board.Content = item;
                            break;

                        default:
                            break;
                        }
                        #endregion switch case
                    }
                }

                board.StateFlag    = StateFlags.Use;
                board.DateCreated  = DateTime.Now;
                board.DateModified = DateTime.Now;

                // 게시판 등록
                db.Boards.Add(board);
                int num = await this.db.SaveChangesAsync();

                // 게시판 파일 등록
                foreach (var item in boardFiles)
                {
                    item.BoardNo = board.BoardNo;
                }

                db.BoardFiles.AddRange(boardFiles);
                int num1 = await this.db.SaveChangesAsync();

                list.Add(board);
                petterResultType.IsSuccessful = true;
                petterResultType.JsonDataSet  = list;
            }
            else
            {
                petterResultType.IsSuccessful = false;
                petterResultType.JsonDataSet  = null;
            }

            return(Ok(petterResultType));
        }
Example #21
0
        public ActionResult m_photo_action()
        {
            int    cate = 7;
            string web_department_id = Request.Cookies["web_department_id"].Value ?? "";
            string machine_id        = Request["machine_id"] ?? "";
            int    project_id        = 0;

            if (!string.IsNullOrEmpty(Request["project_id"]))
            {
                project_id = Convert.ToInt32((Request["project_id"]));
            }


            HttpRequest httpRequest = System.Web.HttpContext.Current.Request;

            int    file_count = httpRequest.Files.Count;
            string title      = Request["title"] ?? "";


            var           fm    = new FileManager();
            List <string> files = fm.PhotoFileUpload(web_department_id);


            int count = 0;

            foreach (string file in files)
            {
                #region 포토게시판 기록

                int BD_idx = db.Board.Any() ? db.Board.Max(a => a.BD_idx) + 1 : 1;

                var _insert = new supertalentoftheworld.Models.Board
                {
                    BD_BM_idx  = cate,
                    BD_title   = title,
                    BD_writer  = User.Identity.Name,
                    BD_hit     = 0,
                    BD_wdate   = DateTime.Now,
                    BD_useable = 1,
                    machine_id = machine_id,
                    project_id = project_id
                };
                db.Board.Add(_insert);
                db.SaveChanges(); // 실제로 저장

                #endregion

                var bf = new BoardFile();
                bf.BF_BD_idx     = BD_idx;
                bf.BF_name       = file;
                bf.BF_useable    = 1;
                bf.BF_wdate      = DateTime.Now;
                bf.BF_type       = "P";
                bf.BD_BM_idx     = cate;
                bf.department_id = web_department_id;
                bf.machine_id    = machine_id;
                bf.main_img      = "N";
                bf.project_id    = project_id;
                bf.user_id       = User.Identity.Name;
                bf.file_title    = title;


                db.BoardFile.Add(bf);


                count++;
            }
            db.SaveChanges();

            //


            string returnUrl = "/board/m_photo_list?cate=7";

            return(Redirect(returnUrl));


            //return Content("<script>location.href='"+ returnUrl + "';</script>");
        }