fix: shop name can not be shared

This commit is contained in:
Damien Ostler 2024-02-19 00:10:54 -05:00
parent 2d230f302c
commit b3fb3dbfe9

View File

@ -61,6 +61,10 @@ public class SellerProfileController : Controller
return BadRequest(); return BadRequest();
return Unauthorized(); return Unauthorized();
} }
if (_dbContext.UserSellerProfiles.Any(x => x.Name.ToLower() == model.Name.ToLower()))
return BadRequest();
var updatedSellerProfile = model.ToModel(existingSellerProfile); var updatedSellerProfile = model.ToModel(existingSellerProfile);
updatedSellerProfile = _dbContext.UserSellerProfiles.Update(updatedSellerProfile).Entity; updatedSellerProfile = _dbContext.UserSellerProfiles.Update(updatedSellerProfile).Entity;
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
@ -100,7 +104,8 @@ public class SellerProfileController : Controller
public async Task<IActionResult> UpdateSellerProfilePage([FromBody]SellerProfilePageSettingsModel model) public async Task<IActionResult> UpdateSellerProfilePage([FromBody]SellerProfilePageSettingsModel model)
{ {
var userId = User.GetUserId(); var userId = User.GetUserId();
var existingSellerProfile = await _dbContext.UserSellerProfiles.Include(x=>x.SellerProfilePageSettings).FirstOrDefaultAsync(sellerProfile=>sellerProfile.UserId==userId); var existingSellerProfile = await _dbContext.UserSellerProfiles
.Include(x=>x.SellerProfilePageSettings).FirstOrDefaultAsync(sellerProfile=>sellerProfile.UserId==userId);
if (existingSellerProfile == null) if (existingSellerProfile == null)
{ {
var sellerProfileRequest = await _dbContext.SellerProfileRequests.FirstOrDefaultAsync(request=>request.UserId==userId && request.Accepted==false); var sellerProfileRequest = await _dbContext.SellerProfileRequests.FirstOrDefaultAsync(request=>request.UserId==userId && request.Accepted==false);