示例#1
0
        public async Task <IActionResult> QnaEdit(Qna qna)
        {
            if (qna != null)
            {
                qna.m_name = User.Identity.Name;

                var file = await UploadFile(HttpContext);

                if (file != null)
                {
                    qna.m_filesize  = file.FileSizeInKB;
                    qna.m_file_guid = file.GuidName;
                    qna.m_file_name = file.OriginalFileName;
                }

                //if qna contains m_ref it means user is submitting answer.
                if (qna.m_ref.HasValue && qna.m_ref.Value > 0)
                {
                    if (qna.Id == qna.m_ref.Value)
                    {
                        qna.Id = 0;
                    }
                }

                if (qna.Id > 0)
                {
                    try
                    {
                        qna.m_date = DateTime.Now;
                        await _qnaService.UpdateQna(qna);

                        TempData["SuccessMsg"] = "성공적으로 저장되었습니다.";
                        return(RedirectToAction("Qna"));
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "PASSWORD-NOT-MATCHED")
                        {
                            TempData["ErrorMsg"] = "비밀번호가 일치하지 않습니다.";
                        }
                        else if (ex.Message == "PASSWORD-EMPTY")
                        {
                            TempData["ErrorMsg"] = "비밀번호를 입력하세요.";
                        }
                        else
                        {
                            TempData["ErrorMsg"] = ex.Message;
                            //ModelState.AddModelError(string.Empty, ex.Message);
                        }
                    }
                }
                else
                {
                    qna.m_date = DateTime.Now;
                    qna.m_read = 0;
                    try
                    {
                        await _qnaService.AddQna(qna);

                        TempData["SuccessMsg"] = "성공적으로 저장되었습니다.";
                        return(RedirectToAction("Qna"));
                    }
                    catch (Exception ex)
                    {
                        TempData["ErrorMsg"] = ex.Message;
                    }
                }
            }
            return(View(qna));
        }
示例#2
0
        //[Authorize(Roles = "Administrators")]
        public async Task <IActionResult> QnaEdit(Qna qna)
        {
            if (qna != null)
            {
                if (User.Identity.IsAuthenticated)
                {
                    if (User.IsInRole("Administrators"))
                    {
                        qna.m_name = "HNS";
                    }
                    else
                    {
                        qna.m_name = User.Identity.Name;
                    }
                }


                var file = await UploadFile(HttpContext);

                if (file != null)
                {
                    qna.m_filesize  = file.FileSizeInKB;
                    qna.m_file_guid = file.GuidName;
                    qna.m_file_name = file.OriginalFileName;
                }

                if (qna.Id > 0)
                {
                    try
                    {
                        qna.m_date = DateTime.Now;
                        await _qnaService.UpdateQna(qna);

                        TempData["SuccessMsg"] = "저장되었습니다.";
                        return(RedirectToAction("Qna"));
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "PASSWORD-NOT-MATCHED")
                        {
                            TempData["ErrorMsg"] = "비밀번호가 일치하지 않습니다.";
                        }
                        else
                        {
                            TempData["ErrorMsg"] = ex.Message;
                        }
                    }
                }
                else
                {
                    qna.m_date = DateTime.Now;
                    qna.m_read = 0;
                    try
                    {
                        await _qnaService.AddQna(qna);

                        TempData["SuccessMsg"] = "저장되었습니다.";
                        return(RedirectToAction("Qna"));
                    }
                    catch (Exception ex)
                    {
                        TempData["ErrorMsg"] = ex.Message;
                    }
                }
            }
            return(View(qna));
        }