Building a Chat Web App With Signal R, Part 2: Listing 2

The PersonHub Update method.

public bool Update(Person updatedPerson)
 {
     bool result = false;

     try
     {
         using (var context = new PersonContext())
         {
             var existingPerson = context.People.FirstOrDefault(x => x.Id == updatedPerson.Id);

             if (existingPerson != null)
             {
                 existingPerson.FirstName = updatedPerson.FirstName;
                 existingPerson.LastName = updatedPerson.LastName;
                 existingPerson.Email = updatedPerson.Email;
                 context.SaveChanges();
                 Clients.All.personUpdated(existingPerson);
                 result = true;
             }
         }
     }
     catch (Exception)
     {
         Clients.Caller.raiseError("Unable to update the Person.");
     }

     return result;
 }

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at [email protected].

comments powered by Disqus

Featured

  • Project Oqtane Provides Blazor-Based Modern App Framework

    The .NET Foundation recently shined a spotlight on Project Oqtane, a modern application framework for Blazor, Microsoft's red-hot open source project that enables web development in C#.

  • Radzen Open Sources 60+ Blazor Components

    Radzen, a development tooling vendor that provides third-party components for .NET coders, open sourced its controls for Blazor, Microsoft's red-hot open source project that enables web development in C#.

  • Customize Your Own Audio Test Cues in Visual Studio 2019 v16.9 Preview 3

    Yes, developers can be alerted to a failed test with a fart sound.

  • Progress Touts New Third-Party Blazor UI Components

    Third-party dev tool specialist Progress announced an update to its .NET-centric offerings, touting new controls for Blazor, Microsoft's red-hot project for creating web apps with C#.

Upcoming Events