Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:01:44+00:00 2026-05-23T10:01:44+00:00

Following actions needs to be performed: get a view from the database of users

  • 0

Following actions needs to be performed:

  • get a view from the database of users that needs to recieve an e-mail
  • send this email
  • update the records of the usres with a timestamp the email was send.

This code does as described above but in the wrong order (rough sketch/needs refactoring):

public class MailMessageController
{
  public static IEnumerable<Invitation> GetInvitations()
  {
     using (boDataContext context = new boDataContext())
     {
        // the table where the timestamps have to be set
        Table<Computer> computer = context.GetTable<Computer>();
        // the view that contains the users email addresses
        Table<Invitation> report = context.GetTable<Invitation>();
        // get the view from the database
        IEnumerable<Invitation> items = report.AsEnumerable<Invitation>();
        foreach (Invitation item in items)
        {
           // update the timestamp (not good, the e-mail hasn't been sent)
           Computer c = computer.FirstOrDefault(
                  i => i.ComputerID == item.ComputerID
           );
           if (c != null)
           {
               c.DateInvited = DateTime.Now;
           }
           yield return item;
        }
        context.SubmitChanges(); // <-- this should commit the changes
    }
 }

I send e-mails from this collections via:

foreach(Invitation item in MailMessageController.GetInvitations())
{
  if (SendMessage(item)) // <<-- bool if message was sent successfully
  {
     // here I want to update the database with the timestamp
  }
}

So I need to update the database with a timestamp after the e-mail was send succesfully.
But it seems that I can’t get around the fact that I need to create a context for every instance I need to update.

So this is more of a design issue. How can I get the view from the database, send emails and update the timestamp in the most fluent and less-cost manner?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:01:45+00:00Added an answer on May 23, 2026 at 10:01 am

    How about updating the timestamps outside the loop?

    var timeStamps = new List<Tuple<DateTime, int>>();
    foreach(Invitation item in MailMessageController.GetInvitations())
    {
      if (SendMessage(item)) // <<-- bool if message was sent successfully
      {
         timeStamps.Add(new Tuple<DateTime, int>(DateTime.Now, item.ID);
      }
    }
    UpdateTimeStamps(timeStamps);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement a post build event that performs the following actions
I have two database tables with the following structure: actions: action_id int(11) primary key
I'm writing powershell script that simulates actions performed by user on the page. I
I want to perform the following actions from inside .NET code: Create a self-signed
Instinctively, I would say that this is impossible, as NHibernate needs to know some
I'd like to script, preferably in rake, the following actions into a single command:
The following code is in the /Courses/Detail action: [AcceptVerbs(GET)] public ActionResult Detail(int id) {
I have a view where I want to perform different actions on the items
Problem Description: Occassionally when debugging, I get the following error. I'm using visual studio
Please can someone tell me the technique that would be used, for the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.