Exemple #1
0
 public ActionResult Edit(AccountGroup item)
 {
     if (ModelState.IsValid)
     {
         var error = AccountGroupDbContext.getInstance().edit(item);
         if (error != null)
         {
             ModelState.AddModelError("", error);
             ViewBag.AccessibleCategoryList = getAccessibleCategories(item.AccessibleCategories);
             return(View(item));
         }
         else
         {
             ModelState.Clear();
             ViewBag.AccessibleCategoryList = getAccessibleCategories(item.AccessibleCategories);
             ViewBag.Message = "Edit '" + item.Name + "' successfully";
             return(View(item));
         }
     }
     else
     {
         ViewBag.AccessibleCategoryList = getAccessibleCategories(item.AccessibleCategories);
         return(View(item));
     }
 }
Exemple #2
0
        public ActionResult Edit(int id = 0)
        {
            var item = AccountGroupDbContext.getInstance().findGroupByID(id);

            ViewBag.AccessibleCategoryList = getAccessibleCategories(item.AccessibleCategories);
            return(View(item));
        }
Exemple #3
0
        public ActionResult Delete(int id = 0)
        {
            var item = AccountGroupDbContext.getInstance().findGroupByID(id);

            if (item == null)
            {
                return(HttpNotFound());
            }
            return(View(item));
        }
Exemple #4
0
        public ActionResult List()
        {
            var items = AccountGroupDbContext.getInstance().findGroups();

            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"];
            }

            return(View(items));
        }
Exemple #5
0
        public ActionResult DeleteConfirmed(int id = 0)
        {
            var item = AccountGroupDbContext.getInstance().findGroupByID(id);

            if (item == null)
            {
                return(HttpNotFound());
            }
            var name  = item.Name;
            var error = AccountGroupDbContext.getInstance().delete(item);

            if (error != null)
            {
                TempData["Message"] = error;
                return(RedirectToAction("List"));
            }
            else
            {
                TempData["Message"] = "Delete '" + item.Name + "' successfully";
                return(RedirectToAction("List"));
            }
        }
Exemple #6
0
        public ActionResult Create(AccountGroup item)
        {
            if (ModelState.IsValid)
            {
                item.isDefaultGroup = false;
                var error = AccountGroupDbContext.getInstance().create(item);
                if (error != null)
                {
                    ModelState.AddModelError("", error);
                    ViewBag.AccessibleCategoryList = getAccessibleCategories();
                    return(View());
                }
                else
                {
                    ModelState.Clear();
                    TempData["Message"] = item.Name + " successfully created.";
                    return(RedirectToAction("List"));
                }
            }

            ViewBag.AccessibleCategoryList = getAccessibleCategories();
            return(View());
        }
Exemple #7
0
        protected override void Seed(WebApplication2.Context.BaseDbContext context)
        {
            Models.AccountGroup accountGroup = null;
            if (!AccountGroupDbContext.getInstance().isDefaultGroupExists())
            {
                AccountGroupDbContext.getInstance().create(
                    new Models.AccountGroup
                {
                    Name           = "Default Group",
                    isDefaultGroup = true,
                }
                    );

                accountGroup = AccountGroupDbContext.getInstance().getDefaultGroup();
            }
            else
            {
                accountGroup = AccountGroupDbContext.getInstance().getDefaultGroup();
            }

            if (!AccountDbContext.getInstance().isSuperadminExists())
            {
                AccountDbContext.getInstance().tryRegisterAccount(
                    new Models.Account
                {
                    Username        = "******",
                    Email           = "*****@*****.**",
                    Role            = "superadmin",
                    GroupID         = accountGroup.AccountGroupID,
                    Firstname       = "super",
                    Lastname        = "admin",
                    Password        = "******",
                    ConfirmPassword = "******",
                    isEnabled       = true,
                },
                    true
                    );
            }
            if (!AccountDbContext.getInstance().isEditorExists())
            {
                AccountDbContext.getInstance().tryRegisterAccount(
                    new Models.Account
                {
                    Username        = "******",
                    Email           = "*****@*****.**",
                    Role            = "editor",
                    GroupID         = accountGroup.AccountGroupID,
                    Firstname       = "editor",
                    Lastname        = "editor",
                    Password        = "******",
                    ConfirmPassword = "******",
                    isEnabled       = true,
                },
                    true
                    );
            }
            if (!AccountDbContext.getInstance().isApproverExists())
            {
                AccountDbContext.getInstance().tryRegisterAccount(
                    new Models.Account
                {
                    Username        = "******",
                    Email           = "*****@*****.**",
                    Role            = "approver",
                    GroupID         = accountGroup.AccountGroupID,
                    Firstname       = "approver",
                    Lastname        = "approver",
                    Password        = "******",
                    ConfirmPassword = "******",
                    isEnabled       = true,
                },
                    true
                    );
            }
            if (!AccountDbContext.getInstance().isPublisherExists())
            {
                AccountDbContext.getInstance().tryRegisterAccount(
                    new Models.Account
                {
                    Username        = "******",
                    Email           = "*****@*****.**",
                    Role            = "publisher",
                    GroupID         = accountGroup.AccountGroupID,
                    Firstname       = "publisher",
                    Lastname        = "publisher",
                    Password        = "******",
                    ConfirmPassword = "******",
                    isEnabled       = true,
                },
                    true
                    );
            }


            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
Exemple #8
0
        SelectList getAccountGroupsForSelect(int?selectedID = null)
        {
            var items = AccountGroupDbContext.getInstance().findGroups();

            return(new SelectList(items, "AccountGroupID", "Name", selectedID));
        }
        public static bool NotifyAllOnActionOfBaseArticle(string categoryStr, BaseArticle baseArticle, EmailNotificationAction action, List <Object> parameters = null)
        {
            if (action == EmailNotificationAction.UNKNOWN)
            {
                return(false);
            }

            var      categoryID = baseArticle.categoryID;
            Category category   = null;

            if (baseArticle.categoryID == null || baseArticle.categoryID <= 0)
            {
                category = InfrastructureCategoryDbContext.getInstance().findCategoryByID(categoryID);
            }



            // get createdBy
            Account owner = AccountDbContext.getInstance().findAccountByID(SessionPersister.account.AccountID);



            // analyze category for interested accounts (by account group)
            List <AccountGroup> accountGroups         = AccountGroupDbContext.getInstance().findGroups();
            List <AccountGroup> filteredAccountGroups = new List <AccountGroup>();

            foreach (var group in accountGroups)
            {
                List <int> categoryIDs = group.getAccessibleCategoryListInt();
                if (category != null && categoryIDs.Contains(category.ItemID))
                {
                    filteredAccountGroups.Add(group);
                }
            }


            List <Account> accounts = AccountDbContext.getInstance().findAccountsByAccountGroupsToEmailNotify(filteredAccountGroups, baseArticle);

            // filter...
            List <Account> filteredAccounts = new List <Account>();

            if (action == EmailNotificationAction.CREATE ||
                action == EmailNotificationAction.EDIT ||
                action == EmailNotificationAction.EDITPROPERTIES ||
                action == EmailNotificationAction.CREATENEWVERSION)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }
            if (action == EmailNotificationAction.DELETE)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }

            if (action == EmailNotificationAction.SUBMITFORAPPROVAL)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }

            if (action == EmailNotificationAction.APPROVE ||
                action == EmailNotificationAction.UNAPPROVE)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover() || acc.isRolePublisher())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }

            if (action == EmailNotificationAction.PUBLISH ||
                action == EmailNotificationAction.UNPUBLISH)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover() || acc.isRolePublisher())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }

            foreach (var acc in filteredAccounts)
            {
                // send to owner?
                if (owner != null && owner.AccountID == acc.AccountID &&
                    owner.ShouldEmailNotifyBaseArticleChangesByOwn())
                {
                    SendEmail(categoryStr, owner, acc, baseArticle, category, action);
                    continue;
                }

                // send to all?
                if (acc.ShouldEmailNotifyBaseArticleChanges())
                {
                    SendEmail(categoryStr, owner, acc, baseArticle, category, action);
                    continue;
                }
            }

            return(true);
        }