コード例 #1
0
        public string AddDashboardItems(DashboardItem dashItem, ModelStateDictionary ModelState)
        {
            Exception accessorError = null;

            if (ModelState.IsValid)
            {
                if (dashItem.DashboardItemID == 0) // creating new item
                {
                    accessorError = accessor.InsertDashItem(dashItem);
                }
                else // editing pre-existing item
                {
                    accessorError = accessor.UpdateDashItem(dashItem);
                }

                if (accessorError == null)
                {
                    return("/DashManager");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "DB Error: " + accessorError.Message);
                }
            }
            return(JsonConvert.SerializeObject(ToolEngine.GetErrorMessages(ModelState)));
        }
コード例 #2
0
        public string addDashboard(Dashboard dash, ModelStateDictionary ModelState)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (dash.DashboardID == 0)
                    {
                        accessor.InsertDashboard(dash); // if any error from insert, add to error list
                    }
                    else
                    {
                        accessor.UpdateDashboard(dash); // if any error from insert, add to error list
                    }
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }


            if (ModelState.ErrorCount == 0)
            {
                return("/DashManager");
            }
            else
            {
                var messages = ToolEngine.GetErrorMessages(ModelState);
                return(JsonConvert.SerializeObject(messages)); // returns string list of errors for page to display, errors based on model specifications
            }
        }
コード例 #3
0
        public string AddDashboardWithPriv(Dashboard dash, ModelStateDictionary ModelState,
                                           List <string> usersWhoCanEdit)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (dash.DashboardID == 0)
                    {
                        var insertedDashID = accessor.InsertDashboard(dash); // if any error from insert, add to error list

                        foreach (var userID in usersWhoCanEdit)
                        {
                            accessor.AddDashPrivilege(insertedDashID, userID);
                        }
                    }
                    else
                    {
                        accessor.RemoveAllPrivilegesOnDashboard(dash.DashboardID.ToString()); // gives us a clean slate to add new privileges

                        foreach (var userID in usersWhoCanEdit)
                        {
                            accessor.AddDashPrivilege(dash.DashboardID.ToString(), userID); // adds privileges
                        }

                        accessor.UpdateDashboard(dash); // if any error from insert, add to error list
                    }
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }


            if (ModelState.ErrorCount == 0)
            {
                return("/DashManager"); // no errors, redirect user
            }
            else
            {                                                  // if errors, convert them to a list to display
                var messages = ToolEngine.GetErrorMessages(ModelState);
                return(JsonConvert.SerializeObject(messages)); // returns string list of errors for page to display, errors based on model specifications
            }
        }
コード例 #4
0
        public async Task <string> AddUser(AddUser newUser, ModelStateDictionary ModelState)
        {
            if (ModelState.IsValid)
            {
                User user = new User
                {
                    UserName = newUser.Email,
                    Email    = newUser.Email
                };

                var result = await _userManager.CreateAsync(user, newUser.Password);

                if (result.Succeeded && newUser.DashPrivileges != null)                                  // add dash privileges
                {
                    string userID = _userManager.Users.Where(x => x.Email == user.Email).ToList()[0].Id; // get the id of the user we just created todo: cleaner

                    var errorMessage = AddDashPrivileges(userID, newUser.DashPrivileges);
                    if (errorMessage != "")
                    {
                        ModelState.AddModelError(string.Empty, errorMessage);
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description); // add errors to our list that we will send our UI
                    }
                }
            }

            if (ModelState.ErrorCount == 0)
            {
                return("/UserManager"); // sending back a url will notify UI to change pages
            }


            var messages = ToolEngine.GetErrorMessages(ModelState);

            return(JsonConvert.SerializeObject(messages)); // returns string list of errors for page to display, errors based on model specifications
        }
コード例 #5
0
        public async Task <string> Login([FromForm] Login info)
        {
            if (ModelState.IsValid)
            {
                var result = await _signInManager.PasswordSignInAsync(info.Email, info.Password,
                                                                      info.RememberMe,
                                                                      lockoutOnFailure : false);


                if (result.Succeeded)
                {
                    return("/DashManager");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Login Failed");
                }
            }

            return(JsonConvert.SerializeObject(ToolEngine.GetErrorMessages(ModelState))); // returns string list of errors for page to display, errors based on model specifications
        }