I have an issue understanding something here. I'm trying to manipulate a field from an entity that is being created, but it is not working as expected.
In short I'm trying to change a field that has emails by splitting them and then adding a ;
separator to distinguish the different emails before saving to the database.
This is my code:
public async Task<IActionResult> OnPost(Models.Requests.Request newRequest)
{
newRequest.RequestStatusID = (int)RequestStatusEnum.Requested;
newRequest.CreatedBy = User.Identity.Name;
newRequest.CreatedDate = DateTime.Now;
newRequest.LastRequestDate = DateTime.Now;
if (!String.IsNullOrEmpty(newRequest.CCRecipients))
{
string[] emailSeparators;
string ccRecipients = "";
emailSeparators = newRequest.CCRecipients.Split(new Char[] { ' ', ',', ';' });
foreach (var email in emailSeparators)
{
//ccRecipients.Concat(email + "; ");
// I have tried two different ways to concatenate the string
ccRecipients = email.Trim() + "; ";
}
// This is where I'm trying to manipulate the string into the field
// To my understanding this is possible but I could be wrong
newRequest.CCRecipients = ccRecipients;
}
await _changeControlContext.AddAsync(newRequest);
await _changeControlContext.SaveChangesAsync();
// Other code that is being done
return new RedirectToPageResult("RedirectsToAnotherPage");
}
There's probably a better way to handle this but for now I want to understand why this is not working or what am I over looking.
In theory it should work but it is not. What could be the issue here?
EDIT: when I mean not working i mean that the values of CCRecipients
field of said request are not being save in the database.
For example: RandomEmail@test.com; RandomEmail2@test.com
. But in the database, nothing appears is stored. It's a white space instead of null. Sorry for the lack of clarity