schwartzmj
schwartzmj
Explore posts from servers
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
I appreciate the help!
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
yea - i was hoping that this just existed in EF and I wasn't finding it
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
Thanks — I saw this while I was searching around but I'm hesitant to add libraries without understanding all my options, but I'll look more into it
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
Yeah I can imagine... I appreciate the help. I think I'll just add the unique checks before the create/update and call it a day
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
(if i wanted to simplify this and keep moving)
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
So basically, do a check on the slug and return a helpful error if it is taken. If the unlikely scenario happens where its taken right after the check, then just return a generic exception since it will probably never happen anyway
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
Ok, thanks. So I might be best off making some sort of helper and re-using it in my services like this?
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
this could still error after checking though (theoretically — if one was created in between)
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
i've created a few helpers as you can see here, but i'm hoping to return some helpful information in my exception
36 replies
CC#
Created by schwartzmj on 8/12/2024 in #help
Catching unique constraint violations and returning the field(s) violating it in a "service" class
public async Task<Result<PostDto>> CreatePost(PostUpsertDto newPostDto)
{
try
{
var newPost = await dbContext.Posts.AddAsync(newPostDto.ToEntity());
await dbContext.SaveChangesAsync();
return Success(PostDto.FromPost(newPost.Entity));
} catch (DbUpdateException)
{
return Failure<PostDto>(new ErrorDetails("...", ErrorCode.Conflict));
}
}
public async Task<Result<PostDto>> CreatePost(PostUpsertDto newPostDto)
{
try
{
var newPost = await dbContext.Posts.AddAsync(newPostDto.ToEntity());
await dbContext.SaveChangesAsync();
return Success(PostDto.FromPost(newPost.Entity));
} catch (DbUpdateException)
{
return Failure<PostDto>(new ErrorDetails("...", ErrorCode.Conflict));
}
}
36 replies
CC#
Created by schwartzmj on 4/26/2024 in #help
URL Parameters and/or data loading in layout files
if i have to do the logic in a page anyway
13 replies
CC#
Created by schwartzmj on 4/26/2024 in #help
URL Parameters and/or data loading in layout files
im probably best off just not creating a layout file and instead a layout component that i just wrap every page with.
13 replies
CC#
Created by schwartzmj on 4/26/2024 in #help
URL Parameters and/or data loading in layout files
ah ok. i read about cascading parameters a bit but it seemed like not a great solution having to perform the same logic in every single child of a layout when all i want is a path parameter 😦
13 replies
CC#
Created by schwartzmj on 4/26/2024 in #help
URL Parameters and/or data loading in layout files
I'd like to essentially do the opposite - read a value in the layout from the page (in this case a URL parameter)
13 replies
CC#
Created by schwartzmj on 4/16/2024 in #help
Redirect after form POST Blazor Static
my current code catches the error and does nothing with it. moving it outside of the try/catch works
14 replies
CC#
Created by schwartzmj on 4/16/2024 in #help
Redirect after form POST Blazor Static
@D.Mentia figured it out 😎 . The NavigateTo method throws if the page is statically rendered. this exception is meant to get caught by the framework to handle the redirect
14 replies
CC#
Created by schwartzmj on 4/16/2024 in #help
Redirect after form POST Blazor Static
cant seem to use methods like RedirectToPage in a @code { } block or blazor code behind file
14 replies
CC#
Created by schwartzmj on 4/16/2024 in #help
Redirect after form POST Blazor Static
i assumed i could have the browser receive a redirect response from the post request like a normal page
14 replies
CC#
Created by schwartzmj on 4/16/2024 in #help
Redirect after form POST Blazor Static
if i change the rendering mode, it works. but it will only work with javascript enabled (essentially becoming a SPA)
14 replies
CC#
Created by schwartzmj on 4/16/2024 in #help
Redirect after form POST Blazor Static
I'm looking to get Razor Pages like functionality for forms
14 replies