Beispiel #1
0
        public async Task <IActionResult> OnPostRestoreVersionAsync(Cmdb item)
        {
            string   dateString;
            DateTime dateValue;

            string currentUser = HttpContext.User.Identity.Name;

            currentUser = currentUser.Remove(0, 4).Replace('.', ' ');

            dateString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            dateValue  = DateTime.Parse(dateString);

            Cmdb            = item;
            Cmdb.Modified   = dateValue;
            Cmdb.ModifiedBy = currentUser;

            _context.Attach(Cmdb).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CmdbExists(Cmdb.CmdbID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            string   dateString;
            DateTime dateValue;

            string currentUser = HttpContext.User.Identity.Name;

            currentUser = currentUser.Remove(0, 4).Replace('.', ' ');

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            dateString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            dateValue  = DateTime.Parse(dateString);

            Cmdb.Modified   = dateValue;
            Cmdb.ModifiedBy = currentUser;

            _context.Attach(Cmdb).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                //Send Update Notification Email to Custodian
                if (Cmdb.Custodian != null)
                {
                    var custodian = Cmdb.Custodian;
                    custodian = custodian.Replace(' ', '.') + "@noaa.gov";

                    var message = new MimeMessage();
                    message.From.Add(new MailboxAddress("CMDB\u207A", "*****@*****.**"));
                    message.To.Add(new MailboxAddress(Cmdb.Custodian, custodian));
                    message.Subject = "Record Update";
                    var url = "http://*****:*****@"Hello " + Cmdb.Custodian + ",\n " +
                               "<br><br>The following record has been updated in CMDB\u207A by " + Cmdb.ModifiedBy + " on " + Cmdb.Modified + ": \n " +
                               "<br><br><a href=" + url + ">" + Cmdb.CdTag + "</a>" +
                               "<br><br>Changes made:" +
                               "<br><br>" + changes
                    };

                    using (var emailClient = new SmtpClient())
                    {
                        emailClient.Connect("smtp.gmail.com", 465, true);
                        emailClient.AuthenticationMechanisms.Remove("XOAUTH2");
                        emailClient.Authenticate("*****@*****.**", "oqcakjfsobdjkwji");
                        emailClient.Send(message);
                        emailClient.Disconnect(true);
                    }
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CmdbExists(Cmdb.CmdbID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/Index"));
        }