using EnvigoHiring.Models.User;
using System.Web.Mvc;

namespace EnvigoHiring.Controllers
{
    [CustomAuthorize(Roles ="Admin")]
    public class userController : Controller
    {
        // GET: user  {scale:values(celsius|fahrenheit)}
        public ActionResult activeusers(string usertype)
        {
            UserModel um = new UserModel();
            um.UserType = 1;
            um.dtUser= um.ViewUser();
            return View(um);
        }
        public ActionResult pendingusers(string usertype)
        {
            UserModel um = new UserModel();
            um.UserType = 0;
            um.dtUser = um.ViewUser();
            return View(um);
        }
        public ActionResult edit(int id)
        {
            UserModel um = new UserModel();
            if (id > 0)
            {
                if (id.ToString() == um.UserID)
                {
                    return Redirect(um.RedirectUrl());
                }
                um.ID = id;
            }
            else
            {
                var url = Request.UrlReferrer;
                return Redirect((url != null && url.ToString() != "") ? url.ToString():"/user/pendingusers");
            }
            var valid= um.FillData();
            if (valid == false)
            {
                var url = Request.UrlReferrer;
                return Redirect((url != null && url.ToString() != "") ? url.ToString() : "/user/pendingusers");
            }
            return View(um);
        }
        [HttpPost]
        public ActionResult edit(UserModel um,int id,string btnSubmit)
        {
            if (id > 0)
            {
                um.ID = id;
            }
            else
            {
                var url = um.RedirectUrl();
                return Redirect(url);
            }
            if (btnSubmit == "Submit")
            {
                um.SaveData();
            }
            var valid = um.FillData();
            if (valid == false)
            {
                var url = um.RedirectUrl();
                return Redirect(url);
            }
            return View(um);
        }
    }
}