Example #1
0
        public ActionResult Login(string username, string password, string team, bool rememberMe)
        {
            Models.User curUser = new Models.User()
            {
                UserName = username,
                Password = password,
                Team     = team
            };
            try
            {
                ValidateModel(curUser); // If not validate, throw invalidoperationexception
                if (db.Set <Models.User>().Where(u => u.UserName == username && u.Password == password && u.Team == team) != null)
                {
                    Session["LoginUser"] = curUser;
                    return(Json(new { result = "ok" }));
                }

                return(Json(new { result = "failed", errorMessage = "Incorrect username or password or team" }));
            }
            catch (DbEntityValidationException vex)
            {
                return(Json(new { result = "failed", errorMessage = vex.Message }));
            }
            catch (InvalidOperationException iex)
            {
                //Check ModelState's error dictionary, and extract them into a object. The covert to a Json and return.
                List <Models.ErrorMessage> errorList = new List <Models.ErrorMessage>();
                foreach (var item in ModelState)
                {
                    Models.ErrorMessage eItem = new Models.ErrorMessage();
                    eItem.Field = item.Key;
                    foreach (var error in item.Value.Errors)
                    {
                        if (error.ErrorMessage != null)
                        {
                            eItem.EMessage += error.ErrorMessage + ";";
                        }
                    }
                    errorList.Add(eItem);
                }

                return(Json(new { result = "failed", errorMessage = errorList }));
            }
            catch (Exception ex)
            {
                return(Json(new { result = "failed", errorMessage = ex.Message }));
            }
        }
Example #2
0
 public AzureIoTHubException(Models.ErrorMessage err) : base(err.Message)
 {
     Error = err;
 }