Exemplo n.º 1
0
        // GET: UploadFiles/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            // 投稿ロック判定
            var isLocked = ControllerHelper.GetSubmitLocked(_context);

            if (isLocked == "1")
            {
                return(NotFound());
            }
            if (id == null)
            {
                return(NotFound());
            }

            var uploadFile = await _context.UploadFiles.FindAsync(id);

            if (uploadFile == null)
            {
                return(NotFound());
            }
            uploadFile.IsPublicOld = uploadFile.IsPublic;
            return(View(uploadFile));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Question,Answer,IsSolved,RelativeNo,CategoryId,IsPublic,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate,IsDeleted")] QaData qaData)
        {
            // 投稿ロック判定
            var isLocked = ControllerHelper.GetSubmitLocked(_context);

            if (isLocked == "1")
            {
                return(NotFound());
            }
            if (id != qaData.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(qaData);
                    await _context.SaveChangesAsync(User.Identity.Name);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!QaDataExists(qaData.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.SelectList = getSelectList(SystemConstants.SystemPatameterMemo, qaData.CategoryId);
            return(View(qaData));
        }
Exemplo n.º 3
0
        // GET: DailyRecords/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            // 投稿ロックかどうか
            ViewData[SystemConstants.IsSubmitLocked] = ControllerHelper.GetSubmitLocked(_context);
            if (id == null)
            {
                return(NotFound());
            }

            var dailyRecord = await _context.DailyRecords
                              .FirstOrDefaultAsync(m => m.Id == id);

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

            // 投稿ロックかどうか
            ViewData[SystemConstants.IsSubmitLocked] = ControllerHelper.GetSubmitLocked(_context);

            // マークダウンをhtmlに変換
            ViewBag.Markdown = Markdown.ToHtml(dailyRecord.Detail);
            return(View(dailyRecord));
        }
Exemplo n.º 4
0
        // GET: DailyRecords/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            // 投稿ロック判定
            var isLocked = ControllerHelper.GetSubmitLocked(_context);

            if (isLocked == "1")
            {
                return(NotFound());
            }
            if (id == null)
            {
                return(NotFound());
            }

            var dailyRecord = await _context.DailyRecords
                              .FirstOrDefaultAsync(m => m.Id == id);

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

            return(View(dailyRecord));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,DocumentDate,Title,Detail,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate,IsDeleted")] DailyRecord dailyRecord)
        {
            // 投稿ロック判定
            var isLocked = ControllerHelper.GetSubmitLocked(_context);

            if (isLocked == "1")
            {
                return(NotFound());
            }
            if (id != dailyRecord.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dailyRecord);
                    await _context.SaveChangesAsync(User.Identity.Name);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DailyRecordExists(dailyRecord.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(dailyRecord));
        }
Exemplo n.º 6
0
        // GET: QaDatas/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            // 投稿ロック判定
            var isLocked = ControllerHelper.GetSubmitLocked(_context);

            if (isLocked == "1")
            {
                return(NotFound());
            }
            if (id == null)
            {
                return(NotFound());
            }

            var qaData = await _context.QaDatas.FindAsync(id);

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

            ViewBag.SelectList = getSelectList(SystemConstants.SystemPatameterMemo, qaData.CategoryId);
            return(View(qaData));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create(List <IFormFile> files, [Bind("Id,Comment,Filename,TmpFilename,IsPublic,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate,IsDeleted")] UploadFile uploadFile)
        {
            // 投稿ロック判定
            var isLocked = ControllerHelper.GetSubmitLocked(_context);

            if (isLocked == "1")
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                // ファイル確認
                if (files.Count == 0)
                {
                    ViewData["Error"] = SystemConstants.NoFileError;
                    return(View(uploadFile));
                }

                // アップロード処理
                foreach (var formFile in files)
                {
                    // 一時ファイルのパスを取得
                    var filePath = Path.GetTempFileName();
                    // 各ファイルについて、ストリームを作成して
                    // その一時ファイルパスにコピー
                    if (formFile.Length > 0)
                    {
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await formFile.CopyToAsync(stream);
                        }
                    }
                    // 保存時は拡張子だけ変えてサーバに置いて、元ファイル名だけ記憶していたら十分だと思います。

                    // サイズ
                    float size = formFile.Length;
                    size            = (float)Math.Round(size / 1024f / 1024f, 2);
                    uploadFile.Size = size;
                    // コメント
                    if (string.IsNullOrEmpty(uploadFile.Comment))
                    {
                        uploadFile.Comment = SystemConstants.NoComment;
                    }
                    // 拡張子
                    var extension = Path.GetExtension(formFile.FileName);   // ".png"とかを取得
                    // 元ファイル名
                    uploadFile.Filename = formFile.FileName;
                    // 一時ファイル名
                    uploadFile.TmpFilename = Path.GetFileNameWithoutExtension(filePath) + extension;
                    // 保存先
                    string targetFile = getTargetPath(uploadFile);

                    // ディレクトリが無ければ作成
                    SafeCreateDirectory(Path.GetDirectoryName(targetFile));    // パスが無ければ作成
                    // 移動
                    System.IO.File.Move(filePath, targetFile);

                    // 登録データ作成
                    var data = new UploadFile();
                    data.Comment     = uploadFile.Comment;
                    data.Filename    = uploadFile.Filename;
                    data.IsPublic    = uploadFile.IsPublic;
                    data.Size        = uploadFile.Size;
                    data.TmpFilename = uploadFile.TmpFilename;
                    data.ContentType = formFile.ContentType;

                    // 登録
                    _context.Add(data);
                }
                await _context.SaveChangesAsync(User.Identity.Name);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(uploadFile));
        }