コード例 #1
0
        public ActionResult ConfirmUserDelete(string id)
        {
            try
            {
                telemetry.TrackPageView("ConfirmUserDelete");

                using (var db = new ProfileInformationDbContext())
                {
                    var currentUsername = User.Identity.Name;

                    telemetry.TrackPageView("ConfirmUserDelete");
                    telemetry.TrackEvent("ConfirmUserDelete", new Dictionary <string, string> {
                        { "User", currentUsername }
                    });

                    var profile = db.Profiles.FirstOrDefault(x => x.ProfileId.ToString() == id);

                    var userModel = new ConfirmUserDeleteViewModel
                    {
                        Name         = currentUsername,
                        Id           = id,
                        Email        = profile.Email,
                        FullName     = profile.FullName,
                        LinkedInLink = profile.LinkedInLink,
                        Project      = profile.Project,
                        Username     = profile.Username
                    };

                    db.AuditLogs.Add(new AuditLog
                    {
                        AuditEvent     = AuditEvent.ViewConfirmDeleteUserPage.ToString(),
                        EventTime      = DateTime.Now,
                        UserAffected   = profile.Username,
                        UserAffectedId = id,
                        Username       = currentUsername
                    });

                    db.SaveChanges();

                    return(View(userModel));
                }
            }
            catch (Exception ex)
            {
                telemetry.TrackException(ex);
                throw;
            }
        }
コード例 #2
0
        public ActionResult DeleteUser(ConfirmUserDeleteViewModel viewModel)
        {
            try
            {
                var currentUsername = User.Identity.Name;

                telemetry.TrackEvent("DeleteUser", new Dictionary <string, string> {
                    { "User", currentUsername }
                });

                using (var db = new ProfileInformationDbContext())
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        var profile = db.Profiles
                                      .Include("Educations")
                                      .Include("AdditionalCourses")
                                      .Include("Languages")
                                      .Include("Companies.Positions.KeyTasks")
                                      .Include("Memberships")
                                      .Include("AdditionalFiles")
                                      .FirstOrDefault(x => x.ProfileId.ToString() == viewModel.Id);

                        db.Profiles.Remove(profile);

                        db.AuditLogs.Add(new AuditLog
                        {
                            AuditEvent     = AuditEvent.DeleteUser.ToString(),
                            EventTime      = DateTime.Now,
                            UserAffected   = profile.Username,
                            UserAffectedId = viewModel.Id,
                            Username       = currentUsername
                        });

                        db.SaveChanges();
                        transaction.Commit();

                        return(RedirectToAction("Overview"));
                    }
                }
            }
            catch (Exception ex)
            {
                telemetry.TrackException(ex);
                throw;
            }
        }