public async Task DeleteAsync(DeleteClientServiceModel model) { var client = await this.context.Clients.FirstOrDefaultAsync(x => x.Id == model.Id && x.SellerId == model.OrganisationId.Value && x.IsActive); if (client == null) { throw new CustomException(this.clientLocalizer.GetString("ClientNotFound"), (int)HttpStatusCode.NotFound); } client.IsActive = false; await this.context.SaveChangesAsync(); }
public async Task <IActionResult> Delete(Guid?id) { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); var serviceModel = new DeleteClientServiceModel { Id = id, Language = CultureInfo.CurrentCulture.Name, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value) }; var validator = new DeleteClientModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { await this.clientsService.DeleteAsync(serviceModel); return(this.StatusCode((int)HttpStatusCode.OK)); } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); }