Ejemplo n.º 1
0
        public ActionResult SetNoMultiaccount(int id)
        {
            UserMultiaccount mua = db.UserMultiaccounts.Include(g => g.UserFrom).Include(g => g.UserTo).Where(x => x.Id == id).FirstOrDefault();

            if (mua == null)
            {
                return(Json(false));
            }

            mua.Status = MultiaccountStatus.FalsePositive;

            db.SetModified(mua);

            Dictionary <string, int> actions  = cache.Get <Dictionary <string, int> >("SystemUserNoteActions");
            Dictionary <int, string> bvsroles = cache.Get <Dictionary <int, string> >("BvsRoles");
            UserNote n = new UserNote()
            {
                AuthorId        = userManager.FindByNameAsync(User.Identity.Name).Id,
                ActionId        = actions["multiaccount"],
                Created         = DateTime.Now,
                IsDeletable     = false,
                RoleIdNeeded    = bvsroles.First(g => g.Value == "Bereichsassistent").Key,
                UserId          = mua.UserFromId,
                Content         = this.RenderViewToString("~/Areas/mitarbeit/Views/_NoteTemplates/NoMultiaccount.cshtml", mua.UserTo.UserName),
                UnparsedContent = ""
            };
            UserNote n2 = new UserNote()
            {
                AuthorId        = userManager.FindByNameAsync(User.Identity.Name).Id,
                ActionId        = actions["multiaccount"],
                Created         = DateTime.Now,
                IsDeletable     = false,
                RoleIdNeeded    = bvsroles.First(g => g.Value == "Bereichsassistent").Key,
                UserId          = mua.UserToId,
                Content         = this.RenderViewToString("~/Areas/mitarbeit/Views/_NoteTemplates/NoMultiaccount.cshtml", mua.UserFrom.UserName),
                UnparsedContent = ""
            };

            db.UserNotes.Add(n);
            db.UserNotes.Add(n2);

            db.SaveChanges();

            return(Json(true));
        }
Ejemplo n.º 2
0
        public ActionResult Multiaccount(int id, UserMultiaccountViewModel umvm)
        {
            User idproof = userManager.FindByIdAsync(id).Result;

            if (idproof == null)
            {
                Response.StatusCode             = 404;
                Response.TrySkipIisCustomErrors = true;
                return(View("~/Areas/mitarbeit/Views/User/_NotFound.cshtml"));
            }

            UserMultiaccountAddViewModel umavm = umvm.MultiaccountToAdd;

            User u2 = userManager.FindByNameAsync(umavm.UserName).Result;

            if (!db.UserMultiaccounts.Any(g => (g.UserFromId == id && g.UserToId == u2.Id) || (g.UserFromId == u2.Id && g.UserToId == id)))
            {
                // if the multiaccount isn't known yet, add it.
                UserMultiaccount um = new UserMultiaccount()
                {
                    UserFromId      = id,
                    UserToId        = u2.Id,
                    ModeratorUserId = userManager.FindByNameAsync(User.Identity.Name).Result.Id,
                    Note            = umavm.Reason,
                    Status          = MultiaccountStatus.Unspecified,
                    Time            = DateTime.Now
                };

                db.UserMultiaccounts.Add(um);

                Dictionary <string, int> actions  = cache.Get <Dictionary <string, int> >("SystemUserNoteActions");
                Dictionary <int, string> bvsroles = cache.Get <Dictionary <int, string> >("BvsRoles");
                UserNote n = new UserNote()
                {
                    AuthorId        = userManager.FindByNameAsync(User.Identity.Name).Id,
                    ActionId        = actions["multiaccount"],
                    Created         = DateTime.Now,
                    IsDeletable     = false,
                    RoleIdNeeded    = bvsroles.First(g => g.Value == "Bereichsassistent").Key,
                    UserId          = um.UserFromId,
                    Content         = this.RenderViewToString("~/Areas/mitarbeit/Views/_NoteTemplates/Multiaccount.cshtml", u2.UserName),
                    UnparsedContent = ""
                };
                UserNote n2 = new UserNote()
                {
                    AuthorId        = userManager.FindByNameAsync(User.Identity.Name).Id,
                    ActionId        = actions["multiaccount"],
                    Created         = DateTime.Now,
                    IsDeletable     = false,
                    RoleIdNeeded    = bvsroles.First(g => g.Value == "Bereichsassistent").Key,
                    UserId          = um.UserToId,
                    Content         = this.RenderViewToString("~/Areas/mitarbeit/Views/_NoteTemplates/Multiaccount.cshtml", idproof.UserName),
                    UnparsedContent = ""
                };
                db.UserNotes.Add(n);
                db.UserNotes.Add(n2);

                db.SaveChanges();
            }
            var accounts = db.UserMultiaccounts.Where(g => g.UserFromId == id || g.UserToId == id)
                           .Include(g => g.UserTo)
                           .Include(g => g.UserFrom)
                           .Include(g => g.Moderator);

            umvm = new UserMultiaccountViewModel()
            {
                Accounts = accounts.ToList(),
                User     = idproof
            };

            return(View("~/Areas/mitarbeit/Views/User/Multiaccounts.cshtml", umvm));
        }