public ActionResult Login(LoginViewModel loginModel)
        {
            if (ModelState.IsValid)
            {
                LoginStatus rslt = qMgr.AllowedToLogin(loginModel);
                var         msg  = string.Empty;
                switch (rslt)
                {
                case LoginStatus.NotFound:
                    msg = ApplicationVariable.GetBrandConfig().LoginPage.ErrorMessageIfUserNotFound.Value;
                    break;

                case LoginStatus.NotAllowed:
                    msg = ApplicationVariable.GetBrandConfig().LoginPage.ErrorMessageIfUserNotAllowedToLogin.Value;
                    break;

                case LoginStatus.Successful:
                    FormsAuthentication.SetAuthCookie(loginModel.FirstName, false);
                    return(RedirectToAction("Search"));

                    break;
                }

                ModelState.AddModelError("EmpId", msg);
            }
            return(View(loginModel));
        }
 public ActionResult Search(SearchViewModel view)
 {
     if (ModelState.IsValid)
     {
         SearchStatus rslt = qMgr.DiscountLookup(view);
         if (rslt == SearchStatus.NotFound)
         {
             ModelState.AddModelError("EmpId", ApplicationVariable.GetBrandConfig().SearchPage.NoResultFound.Value);
         }
     }
     return(View(view));
 }
Example #3
0
        private string LogException(Exception ex)
        {
            string result = string.Empty;

            var logLocation = ApplicationVariable.GetBrandConfig().CustomError.ErrorLogLocation.Value.Trim();

            #region Remove "/" OR "\" if we have
            if (logLocation.StartsWith("/") || logLocation.StartsWith("\\"))
            {
                logLocation = logLocation.Substring(1).Trim();
            }
            #endregion

            if (!string.IsNullOrEmpty(logLocation))
            {
                if (!Path.IsPathRooted(logLocation))
                {
                    logLocation = Server.MapPath(string.Format(@"\{0}", logLocation));
                }

                var fileName = string.Format("Error_{0}.txt", DateTime.Now.ToString("yyyy-MM-dd"));
                var filePath = Path.Combine(logLocation, fileName);

                try
                {
                    if (!Directory.Exists(logLocation))
                    {
                        Directory.CreateDirectory(logLocation);
                    }
                    using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write))
                        using (StreamWriter sw = new StreamWriter(fs))
                        {
                            sw.WriteLine("=======================================================");
                            sw.WriteLine(string.Format("Error Occured at - {0}", DateTime.Now));
                            sw.WriteLine("=======================================================");
                            sw.WriteLine(ex.Message);
                            sw.WriteLine(Environment.NewLine + "Details - ");
                            sw.WriteLine(ex.StackTrace);
                            sw.WriteLine("=======================================================");
                            sw.WriteLine(Environment.NewLine + Environment.NewLine + Environment.NewLine);
                        }
                }
                catch (Exception exc)
                {
                    result = exc.Message;
                }
            }

            return(result);
        }