using EnvigoHiring.Models.Applicants;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using CommonFunc;

namespace EnvigoHiring.Controllers
{
    [CustomAuthorize]
    public class commentsController : Controller
    {
        // GET: comments
        [Route("~/applicants/comments/{ApplicantdID}/{CommentID?}")]
        public ActionResult addcomments(int ApplicantdID,string CommentID)
        {
            ApplicantsComment ac = new ApplicantsComment();
            ac.ApplicantID = ApplicantdID;
            if (CommentID != null)
            {
                if (!CheckFunc.IsNumeric(CommentID))
                {
                    return RedirectToAction("index", "applicants");
                }
            }
            ac.CommentID = CommentID.ToInt32();
            var result= ac.FillData();
            if (result == false)
            {
                return RedirectToAction("index", "applicants");
            }
            return View(ac);
        }
        [HttpPost]
        [Route("~/applicants/comments/{ApplicantdID}/{CommentID?}")]
        public ActionResult addcomments(ApplicantsComment ac,int ApplicantdID, string CommentID, string btnsubmit)
        {
            ac.ApplicantID = ApplicantdID;
            if (CommentID != null)
            {
                if (!CheckFunc.IsNumeric(CommentID))
                {
                    return RedirectToAction("index", "applicants");
                }
            }
            ac.CommentID = CommentID.ToInt32();
            if (btnsubmit == "Submit")
            {
                ac.SaveData();
            }
            ac.FillData();
            return View(ac);
        }
    }
}